rand on 4d broken
Andrew Myers
andru at rhialto.sgi.com
Mon Jun 26 12:07:53 AEST 1989
In article <1551 at cs-spool.calgary.UUCP> paquette at cpsc.ucalgary.ca (Trevor Paquette) writes:
>
> Just to save some people some headaches.. The docs for 'rand'
> on the 4d (and I suspect that the 3000 series also have this
> problem) are WRONG!!
> They state that rand returns a number between 0 and (2^15)-1.
> Well rand returns a number between 0 and 32767. (Which
> I guess is right.. but the numbers do not get above 32767..)
> This caused me some probs on porting some software from the Sun.
>
> Trev
Hmmm. Since 2^15 - 1 = 32767, I'm not sure what your complaint
is here. In any case, you should think twice about using rand()
for generating random numbers. UNIX rand() is well known to
be an extremely poor random number generator. If you are doing
any kind of simulation or numerical analysis work, rand()
will quite possibly bias your results. Unfortunately,
the algorithm, poor as it is, must remain the same for backwards
compatibility.
A much better random number generator is the rand48() set
of functions. I recommend using these instead. drand48()
returns a double in [0,1), and lrand48() returns a long in
[0,2^31). Use srand48() to seed the random number process.
Andrew Myers (andru at sgi.com)
>==============================================================================
> Trevor Paquette/GraphicsLand, Calgary, Alberta
> ..{ubc-cs,utai,alberta}!calgary!paquette ICBM:51 03 N/114 05 W
> calgary!paquette at cs.ubc.ca Luminous beings we are, not this crude matter
More information about the Comp.sys.sgi
mailing list