don@allegra.UUCP (D. Mitchell) (04/17/84)
The random() function in the 4.2 release is quite poor. It failed some statistical tests that we did here, so we looked at the code and found some subtle bugs. What it is trying to do is sound, but the author tried to be clever with pointers and messed up. It is not, in fact, evaluating the polynomial that is claimed in the little TV commercial at the beginning of the source.
earl@mordor.UUCP (04/20/84)
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@s1-c
...!decvax!decwrl!mordor!earl