Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 22 May 2016 13:10:09 +1000 (EST)
From:      Bruce Evans <brde@optusnet.com.au>
To:        Andrey Chernov <ache@freebsd.org>
Cc:        Bruce Evans <brde@optusnet.com.au>, Pedro Giffuni <pfg@freebsd.org>,  cem@freebsd.org, src-committers@freebsd.org, svn-src-all@freebsd.org,  svn-src-head@freebsd.org
Subject:   Re: svn commit: r300377 - head/sys/compat/ndis
Message-ID:  <20160522124923.I1697@besplex.bde.org>
In-Reply-To: <8bd5428f-6955-72c3-0294-72f7ef936e16@freebsd.org>
References:  <201605211752.u4LHqiHQ031457@repo.freebsd.org> <CAG6CVpXjU3tHdar7d=xyr%2BTmffg0NrQu3q7SD=b6%2BjF=yvVr-Q@mail.gmail.com> <a88c14ea-ee78-54de-6142-08a561a49d98@FreeBSD.org> <CAG6CVpV_3%2B%2BWqg2X23=RM942zaDkyL6fxH2YN0TXUqpPjneCOw@mail.gmail.com> <262938a6-50bd-b6f4-24c9-895b837a368e@FreeBSD.org> <20160522091455.A1014@besplex.bde.org> <8bd5428f-6955-72c3-0294-72f7ef936e16@freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20160522124923.I1697>