random()

earl at mordor.UUCP earl at mordor.UUCP
Sat Apr 21 07:09:21 AEST 1984


A recent message to this news group contained some misleading
information about the random number generator random() which is part of
libc.a in 4.2BSD.  While it is true that there is a bug in random() as
distributed, it is not true that there are "some subtle bugs".  The bug
is a static initialization problem which affected the default geneartion
of random numbers (if you call initstate(), the problem disappears).
It is also not true that random() generates "poor" random numbers (if
initstate() is called or if the bug is fixed).  I have done some fairly
extensive testing of random() (using tests mainly from Knuth vol. 2),
and it does as well or better than anything else I've looked at which
runs in comparable time.

The fix is:

------- random.c -------
145c145
< static  long		*state			= &randtbl[ -1 ];
---
> static  long		*state			= &randtbl[ 1 ];
------------------------

						    Earl Cohen
						    earl at s1-c
						...!decvax!decwrl!mordor!earl



More information about the Comp.unix.wizards mailing list