Created
October 7, 2022 07:32
-
-
Save Ajnasz/10bde5ab34ab0dab423d16ace14e1e3e to your computer and use it in GitHub Desktop.
shell function to generate random number from shell using /dev/urandom
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/sh | |
# function to generate random number from shell using /dev/urandom | |
# https://unix.stackexchange.com/questions/268952/using-dev-random-dev-urandom-to-generate-random-data | |
rand() { | |
bytes=${1:-1} | |
od -vAn -N$bytes -tu2 < /dev/urandom | sed 's/\s\+//g' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment