Advertisement
efxtv

bash generate random alphanumeric string

Feb 6th, 2023 (edited)
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | Cybersecurity | 0 0
  1. T.me/efxtv
  2.  
  3. #!/bin/bash
  4. # bash generate random alphanumeric string
  5. #
  6.  
  7. # bash generate random 32 character alphanumeric string (upper and lowercase) and
  8. NEW_UUID=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
  9.  
  10. # bash generate random 32 character alphanumeric string (lowercase only)
  11. cat /dev/urandom | tr -dc 'a-z0-9' | fold -w 32 | head -n 1
  12.  
  13. # Random numbers in a range, more randomly distributed than $RANDOM which is not
  14. # very random in terms of distribution of numbers.
  15.  
  16. # bash generate random number between 0 and 9
  17. cat /dev/urandom | tr -dc '0-9' | fold -w 256 | head -n 1 | head --bytes 1
  18.  
  19. # bash generate random number between 0 and 99
  20. NUMBER=$(cat /dev/urandom | tr -dc '0-9' | fold -w 256 | head -n 1 | sed -e 's/^0*//' | head --bytes 2)
  21. if [ "$NUMBER" == "" ]; then
  22. NUMBER=0
  23. fi
  24.  
  25. # bash generate random number between 0 and 999
  26. NUMBER=$(cat /dev/urandom | tr -dc '0-9' | fold -w 256 | head -n 1 | sed -e 's/^0*//' | head --bytes 3)
  27. if [ "$NUMBER" == "" ]; then
  28. NUMBER=0
  29. fi
Tags: BASH efx tv
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement