Last active
June 7, 2016 12:47
-
-
Save kini/20a0e853a2c32d20310e1484a0a90971 to your computer and use it in GitHub Desktop.
better random numbers for bash
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
random () { | |
# note: $RANDOM only gives 15 bits of entropy, and the apparently | |
# commonly used $RANDOM$RANDOM is non-uniform as it misses such | |
# numbers as 4294967295. This command will grab 4 bytes from | |
# /dev/urandom, interpret them as a 4-byte unsigned integer, and | |
# format them in decimal representation. It can be used as a | |
# replacement for $RANDOM when you want a full 32 bits of entropy. | |
od -An -t u4 -N4 < /dev/urandom | tr -d '[[:space:]]' | |
} | |
export -f random |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks, good point! Might as well throw that in.