Bug in rand() and srand()

Guy Harris guy at rlgvax.UUCP
Thu Mar 7 03:02:46 AEST 1985


> rand uses a 32bit multiplicative random number generator.  These generators
> tend to generate a repeating sequence in the lower bits.  On the pdp 11
> the generator used a long and the returned value was shifted right by 16
> bits to get an int.  The horribly behaved lower bits never hit the user.
> On the vax the how 32 bit item is returned.

Well, to be specific, on the VAX under 4.xBSD the 32 bit item is returned.
The System {III,V} systems still return the upper 16 bits.  This means that any
program that assumes "rand" returns something in the range 0 <= N < MAX16BITINT
will work on all UNIX systems on machines with 16-bit "int"s and on all System
N systems, but won't work right on 4.xBSD systems.  Grumble grumble...
-- 
	Guy Harris
	{seismo,ihnp4,allegra}!rlgvax!guy



More information about the Net.bugs mailing list