Created
February 5, 2022 17:10
-
-
Save hebrides/3fadc588f7ec08a4cbf794449b927165 to your computer and use it in GitHub Desktop.
Generate random alphanumeric text DIGITS long.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This is a simplified version of this script: https://gist.github.com/earthgecko/3089509 | |
# "Random numbers in a range, more randomly distributed than $RANDOM | |
# which is not very random in terms of distribution of numbers." | |
# You may want to add a reference to your .bashrc file, e.g.: | |
# alias rnd="path/to/script/rnd.sh" | |
# macOS fix, ref: https://github.com/projectzeroindia/CVE-2019-19781/issues/3 | |
export LC_CTYPE=C | |
if (( $# != 1 )); then | |
echo "Script syntax: rnd <number of digits>, e.g. rnd 256"; | |
echo "Defaulting to 32 digits"; | |
DIGITS=32 | |
else | |
DIGITS=$1 | |
fi | |
# generate random alphanumeric text DIGITS long | |
cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w $DIGITS | head -n 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment