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'
Code language: Bash (bash)

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')
Code language: Bash (bash)

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

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments