I\'d like to put together a command that will print out a string of 32 hexadecimal digits. I\'ve got a Python script that works:
python -c \'import random ; prin
If you have hexdump
then:
hexdump -n 16 -e '4/4 "%08X" 1 "\n"' /dev/random
should do the job.
Explanation:
-n 16
to consume 16 bytes of input (32 hex digits = 16 bytes).4/4 "%08X"
to iterate four times, consume 4 bytes per iteration and print the corresponding 32 bits value as 8 hex digits, with leading zeros, if needed.1 "\n"
to end with a single newline.Note: this solution uses /dev/random
but it could as well use /dev/urandom
. The choice between the two is a complex question and out of the scope of this answer. If you are not sure, have a look maybe at this other question.