Tcsh Random Number from /Dev/Random and /Dev/Urandom
I Am Trying to Figure out How to Generate Random from Using /Dev/Random and /Dev/Urandom in Tcsh. After I Do Head -C 1 /Dev/Random, I Get a Random Byte. How Do...
I am trying to figure out how to generate random from using /dev/random and /dev/urandom in tcsh. After I do head -c 1 /dev/random, I get a random byte. How do I turn this byte into actual number?
3 Answers
$ head -c 1 /dev/urandom | od -t u1 | cut -c9-
That will give you a random integer between 0 and 255 inclusive.
My apologies for redirecting your question in advance but despite not using it for your script, bash can be handy here if you have it:
bash -c 'echo $RANDOM'
will return a random integer. You can use therefore:
RANDOM=`bash -c 'echo $RANDOM'`
from within a tcsh script to achieve the same variable.
this works in csh OS X -> generate 1 number between 2 and 10 and assign it to random:
set random = `jot -r 1 2 10`
echo "random number $random was generated"