Skip to content

Instantly share code, notes, and snippets.

@mohnish82
Last active March 31, 2016 02:18
Show Gist options
  • Save mohnish82/0226b433430fcb8c4cd75f33eaccffaa to your computer and use it in GitHub Desktop.
Save mohnish82/0226b433430fcb8c4cd75f33eaccffaa to your computer and use it in GitHub Desktop.
Random number generator commandfu
# Method 1
cat /dev/random | tr -dc 'a-zA-Z0-9' | fold -w 8 | head -n 5
tr => translate/delete input stream
-d => delete from stream
-c => complement of SET1, SET1 being 'a-zA-Z0-9' i.e. delete all chars except the ones in SET1 from input stream
fold => wrap output into 16 column fixed width i.e. generate passwords of length 8
head => top 5 results only
This command generates 5 random numbers, each being 8 character long and containing uppercase/lowercase letters and numbers.
# Method 2
cat /dev/urandom | tr -dc [:alnum:] | head -c8; echo
*urandom is non-blocking for entropy unavailability, while random blocks. So, prefer randon.
Credit: https://blog.colovirt.com/2009/01/07/linux-generating-strong-passwords-using-randomurandom/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment