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?
Asked
Active
Viewed 8,050 times
3 Answers
10
$ head -c 1 /dev/urandom | od -t u1 | cut -c9-
That will give you a random integer between 0 and 255 inclusive.

Martin Tournoij
- 26,737
- 24
- 105
- 146
7
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.

mikebabcock
- 791
- 1
- 7
- 20
1
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"

MikeB
- 21
- 1