How to Generate a Random AlphNumeric String in Linux/MacOS


If you need to generate a random AlphaNumeric string from the Linux/MacOS Command-Line, then you can use the following script:

dd if=/dev/random bs=8 count=1 2>/dev/null | od -An -tx1 | tr -d ' \t\n'

This can also be piped into a variable as follows:

RANDOM_ID=$(dd if=/dev/random bs=8 count=1 2>/dev/null | od -An -tx1 | tr -d ' \t\n')

The above echo $RANDOM_ID will resemble something similar to: 90fa3bb51922eadc