Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Random numbers in c shell

3,214 views
Skip to first unread message

Neil Frenette

unread,
Jan 30, 1999, 3:00:00 AM1/30/99
to
Is it possible to generate random numbers in c shell ??


Neil F

Tom Parker

unread,
Jan 31, 1999, 3:00:00 AM1/31/99
to
Neil Frenette (ne...@echelon.ca) wrote:
: Is it possible to generate random numbers in c shell ??

Not directly. But here are a few of indirect ways -- they
use ksh or perl:

set r = `ksh 'echo $RANDOM'`
set r = `perl -e 'srand; print int(rand(200)+1)'`
set r = `perl -e 'print int(rand(100))'`


+--------------------------------------------------------------------+
| Tom Parker | National Center for Atmospheric Research |
| tpa...@ncar.ucar.edu | (303) 497-1227 |
+--------------------------------------------------------------------+

Tom Keats

unread,
Feb 1, 1999, 3:00:00 AM2/1/99
to
Tom Parker wrote:
>
> Neil Frenette (ne...@echelon.ca) wrote:
> : Is it possible to generate random numbers in c shell ??
>
> Not directly. But here are a few of indirect ways -- they
> use ksh or perl:
>
> set r = `ksh 'echo $RANDOM'`
> set r = `perl -e 'srand; print int(rand(200)+1)'`
> set r = `perl -e 'print int(rand(100))'`
>

The `jot` utility might also be of some help (if it's installed
on the poster's sys.)

Checking man jot on my sys, it doesn't say if it's PD or
freely/readily available, tho'.

--
Who should be replaced with an Expert System?

remove NO_SPAM. from address to reply

William Roeder

unread,
Feb 1, 1999, 3:00:00 AM2/1/99
to
Neil Frenette wrote:
>
> Is it possible to generate random numbers in c shell ??
>
> Neil F
I had a script for performance testing, it generated files of random
size from 0 to 2GB (in 34MB increments.) Here's the pertinent part:

@ iosize = ${maxsize}
@ rand = 1
while ( -1 )
@ rand += `date +%S` + ${iosize}
while ( ${rand} > 60 )
@ rand -= 60
end
@ iosize = ( ${rand} * ${maxsize} ) / 60
...

Depending on what your trying to accomplish, this may or may not be
random enough for you.
--
Bill Roeder
If you find yourself in a hole, the first thing to do is stop diggin.

0 new messages