Thursday, December 7, 2023
HomeSoftware EngineeringThe right way to Generate a Random AlphNumeric String in Linux/MacOS

The right way to Generate a Random AlphNumeric String in Linux/MacOS


If that you must generate a random AlphaNumeric string from the Linux/MacOS Command-Line, then you should use the next script:

dd if=/dev/random bs=8 rely=1 2>/dev/null | od -An -tx1 | tr -d ' tn'

This can be piped right into a variable as follows:

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

The above echo $RANDOM_ID will resemble one thing much like: 90fa3bb51922eadc

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments