I am trying to randomize a number with 32 hexadecimal digits in bash with seed which depends on the date.
I thought about something like: RANDOM=$(date %N | cut -b4-9)
, but it's not give me 32 hexadecimal digits.
ideas?
CodePudding user response:
I'm always generating with: openssl rand -base64 32
CodePudding user response:
Feed /dev/urandom
to tr
and delete all but hex digits:
$ tr -dc '[:xdigit:]' < /dev/urandom | head -c32
90D75De9CaA0C38a15B8facf59CBBDdc
If you need all upper (or all lower):
$ tr -dc '0-9A-F' < /dev/urandom | head -c32
CBABC737B0F9C059531CA7672FCA52F6
$ tr -dc '0-9a-f' < /dev/urandom | head -c32
87fa3f2e4f98a8e8eecb8236e2736eba
CodePudding user response:
Eliminate your need for the date.
If it's an assignment, say so.
Assuming it is -
$: src="0123456789ABCDEF" && RANDOM=$(( $(date %s) % 32767 )) &&
> for c in {1..32}; do printf "%s" ${src:$((RANDOM)):1}; done &&
> echo
14E4552562D03BB6FCAC8602B0D38BE7