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 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.

0

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.

0

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"

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like