Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

where is my RANDOM ? 2

Status
Not open for further replies.

stfaprc

Programmer
Feb 10, 2005
216
US
using tcsh 6.12.00

I want to wait a random amount of time in one of my scripts,
but can not figure out how to do so.

[760 /home/second]# service random status
The random data source exists
[761 /home/second]# echo $RANDOM
RANDOM: Undefined variable.
[762 /home/second]# echo $random
random: Undefined variable.

What am I missing / not understanding ?
 
tcsh does not have a builtin $RANDOM, I believe bash and ksh have it. You will need to call bash or the like to get one:

x=`/bin/bash -c 'echo $RANDOM'`
echo $x
 
wow, i would have thought bash/ksh would not have it and tcsh to provide it :)

thanks, that worked out.



 
Or you could use something like this to get a 16-bit random unsigned integer:

Code:
x=`head -2c /dev/random  | od -t u2 -An`

Annihilannic.
 
Geez, thanks. I had no idea that one could read that way from the pseudo device. Cool.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top