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

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

Sophia Al-Mansoor

Sophia Al-Mansoor

Global Business & E-Commerce Reporter

Sophia analyzes international trade, startup ecosystems, retail transformation, and supply chain logistics for modern digital publications.

Share this article
Twitter Facebook Pinterest