[comp.sys.sgi] rand on 4d broken

paquette@cpsc.ucalgary.ca (Trevor Paquette) (06/24/89)

  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

==============================================================================
 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

andru@rhialto.sgi.com (Andrew Myers) (06/26/89)

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

henry@utzoo.uucp (Henry Spencer) (06/28/89)

In article <165@odin.SGI.COM> andru@rhialto.sgi.com (Andrew Myers) writes:
>	... UNIX rand() is well known to
>	be an extremely poor random number generator...

In fairness, the *original* Version 7 rand() wasn't too bad.  Not great,
but not bad.  It was a 32-bit generator that returned the *upper* 16 bits
to avoid the rather non-random behavior of the low-order bits.  Alas, many
of the people who messed with it later didn't appreciate this subtlety.
-- 
NASA is to spaceflight as the  |     Henry Spencer at U of Toronto Zoology
US government is to freedom.   | uunet!attcan!utzoo!henry henry@zoo.toronto.edu