Bug in random number generator

utzoo!decvax!harpo!eagle!mhuxt!mhuxa!mhb5b!smb utzoo!decvax!harpo!eagle!mhuxt!mhuxa!mhb5b!smb
Thu Mar 24 13:46:49 AEST 1983


As Knuth points out (Art of Computer Programming, Vol. 2 -- Seminumerical
Algorithms) the low-order bits of *any* linear congruential random number
generator are not particularly random.  The proper way to view the output
is as a fraction between 0 and 1.  Thus, to get a random bit, one should
never take rand()%2; rather, one should use rand() > (MAXINT/2) (or some
such).

Of course, none of this means that rand() is a good random number generator --
it's not.


		--Steve



More information about the Comp.bugs.4bsd.ucb-fixes mailing list