On Sun, 22 May 2016, Andrey Chernov wrote:

On 22.05.2016 3:06, Bruce Evans wrote:
...
FreeBSD still has the ACM version in libkern, and has a fixed copy
of that in libc, with the bad old version under an ifdef.

The libc version now adjusts the range from [0, 0x7fffffff] to
0, 0x7ffffffd] and reduces RAND_MAX by 2 to match.  The claimed uniformity
for the larger range is very wrong, since the ACM algorithm can only
produce numbers in the range [1(or is it 0?), 0x7ffffffe] starting from a
seed in the range [1, 0x7ffffffe(or is it 1 higher?)].  There are problems
at both extremities, and it isn't clear if the new or old adjustments to
avoid them preserve uniformity.  It is clear that the range was at least
1 too high, since the ACM algorithm does a modulo by 0x7fffffff.

libc version does range adjustment for better uniformity only for
rand(3), not for random(3). There is no RAND_MAX constant in the
random(3) API. POSIX require that random(3) should stay in [0, 2^31-1].

The one in the kernel is random(9) being used to implement rand(9).
This doesn't have to conform to POSIX or be very good.  random(9) is
actually really rand(9) under a different name.  It uses a LCG with a
small period, but random(3) is specified to be the BSD one, with
wording too similar to that in the FreeBSD man page -- it must use
a nonlinear method with a default period of 16 times larger than 2**31-1, and must give a period larger than 2**69 with a state table
size of 256.  The default should have been changed to much more than
16 times larger long before POSIX standardized the 1980's default.

Bruce
_______________________________________________
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to