Skip to content

Instantly share code, notes, and snippets.

@Ajnasz
Created October 7, 2022 07:32
Show Gist options
  • Save Ajnasz/10bde5ab34ab0dab423d16ace14e1e3e to your computer and use it in GitHub Desktop.
Save Ajnasz/10bde5ab34ab0dab423d16ace14e1e3e to your computer and use it in GitHub Desktop.
shell function to generate random number from shell using /dev/urandom
#!/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