AFAIK it's the true source of randomness in any unix.
> I’m not sure the best way to make use of it as a source of random decimals — there are surely a dozen ways to do so — but this works:
`od(1)` will do binary to binary to decimal:
> head -c4 /dev/urandom | od -An -vtu4
4119929390
> head -c4 /dev/urandom | od -An -vtu4
3540752584
> head -c4 /dev/urandom | od -An -vtu4
998126897The use of "true" here seems ambiguous.
Does this statement mean that you discourage creation of cryptographic applications with shell scripts, you discourage use of shell scripts to orchestrate applications that use /dev/urandom for any reason, or something else entirely?
The linked gist doesn't appear to be making the case for using its recommendations in cryptographic applications so what I'm ultimately after is what the commenter thinks is being done in the shell that's inappropriate.
However, all software random number generators are pseudo random, including cryptographic ones. They are called CSPRNGs, which stands for Cryptographically Secure Pseudo Random Number Generator.
My favorite tool for this is "openssl rand" and I can find the manual page on rhel7 with "man rand."
Here are 8 bytes of randomness in base64:
$ openssl rand -base64 8
mGHxYcVOmA8=
When I've got dozens of users to create, this is how I am assigning their initial passwords.The shell's $RANDOM is somewhat less trustworthy than other sources here. It also does not appear to be POSIX, but comes from ksh88, where it is described as returning a random integer between 0 and 32767 each time it is referenced. If unset in a script, it cannot be used again for the life of the shell.
function password_generate { head -c ${1-12} /dev/urandom | base64; } # uname -a
HP-UX prdcrm B.10.20 A 9000/800 862741461 two-user license
# ls -l /dev/urandom
/dev/urandom not found
# openssl rand -base64 8
v51U1RvSD2Q=
I could run this on VAX VMS if you want.https://lwn.net/Articles/889452/
Pragmatically, they are equivalent for most scripting use cases.
RD=$(dc -e 16i`xxd -c $N -g $N -l $N -p /dev/urandom | tr a-f A-F`p)This goes from good practice to necessary as a cron job uses increasing resources or talks to a centralized service.
Puppet implements this as splay: https://www.puppet.com/docs/puppet/7/configuration.html#spla...
I’m not sure the best way to make use of it as a source of random decimals — there are surely a dozen ways to do so — but this works:
As always, my advice for things like this is that if you’re in need of true random numbers in your shell script then you should probably stop writing whatever it is you are writing as a shell script.