earthgecko gist felülvizsgálása 9 years ago. Revízióhoz ugrás
1 file changed, 18 insertions
bash.generate.random.alphanumeric.string.sh
| @@ -7,3 +7,21 @@ NEW_UUID=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1) | |||
| 7 | 7 | ||
| 8 | 8 | # bash generate random 32 character alphanumeric string (lowercase only) | |
| 9 | 9 | cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1 | |
| 10 | + | ||
| 11 | + | # Random numbers in a range, more randomly distributed than $RANDOM which is not | |
| 12 | + | # very random in terms of distribution of numbers. | |
| 13 | + | ||
| 14 | + | # bash generate random number between 0 and 9 | |
| 15 | + | cat /dev/urandom | tr -dc '0-9' | fold -w 256 | head -n 1 | head --bytes 1 | |
| 16 | + | ||
| 17 | + | # bash generate random number between 0 and 99 | |
| 18 | + | NUMBER=$(cat /dev/urandom | tr -dc '0-9' | fold -w 256 | head -n 1 | sed -e 's/^0*//' | head --bytes 2) | |
| 19 | + | if [ "$NUMBER" == "" ]; then | |
| 20 | + | NUMBER=0 | |
| 21 | + | fi | |
| 22 | + | ||
| 23 | + | # bash generate random number between 0 and 999 | |
| 24 | + | NUMBER=$(cat /dev/urandom | tr -dc '0-9' | fold -w 256 | head -n 1 | sed -e 's/^0*//' | head --bytes 3) | |
| 25 | + | if [ "$NUMBER" == "" ]; then | |
| 26 | + | NUMBER=0 | |
| 27 | + | fi | |
earthgecko gist felülvizsgálása 13 years ago. Revízióhoz ugrás
1 file changed, 9 insertions
bash.generate.random.alphanumeric.string.sh(fájl létrehozva)
| @@ -0,0 +1,9 @@ | |||
| 1 | + | #!/bin/bash | |
| 2 | + | # bash generate random alphanumeric string | |
| 3 | + | # | |
| 4 | + | ||
| 5 | + | # bash generate random 32 character alphanumeric string (upper and lowercase) and | |
| 6 | + | NEW_UUID=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1) | |
| 7 | + | ||
| 8 | + | # bash generate random 32 character alphanumeric string (lowercase only) | |
| 9 | + | cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1 | |