Path: utzoo!attcan!uunet!lll-winken!arisia!sgi!shinobu!odin!rhialto!andru From: andru@rhialto.sgi.com (Andrew Myers) Newsgroups: comp.sys.sgi Subject: Re: rand on 4d broken Keywords: Docs are wrong Message-ID: <165@odin.SGI.COM> Date: 26 Jun 89 02:07:53 GMT References: <1551@cs-spool.calgary.UUCP> Sender: news@odin.SGI.COM Organization: Silicon Graphics, Inc., Mountain View, CA Lines: 32 In article <1551@cs-spool.calgary.UUCP> paquette@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@sgi.com) >============================================================================== > Trevor Paquette/GraphicsLand, Calgary, Alberta > ..{ubc-cs,utai,alberta}!calgary!paquette ICBM:51 03 N/114 05 W > calgary!paquette@cs.ubc.ca Luminous beings we are, not this crude matter