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.
0My 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.
0this 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"