How to Generate a Random AlphNumeric String in Linux/MacOS

0 min read 68 words

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

Tags:
Andrew
Andrew

Andrew is a visionary software engineer and DevOps expert with a proven track record of delivering cutting-edge solutions that drive innovation at Ataiva.com. As a leader on numerous high-profile projects, Andrew brings his exceptional technical expertise and collaborative leadership skills to the table, fostering a culture of agility and excellence within the team. With a passion for architecting scalable systems, automating workflows, and empowering teams, Andrew is a sought-after authority in the field of software development and DevOps.

Tags