RAND_MAX broken

Andrey Chernov ache at freebsd.org
Tue Jul 2 15:51:29 UTC 2013


On 02.07.2013 11:39, Bruce Evans wrote:
> The bugs are a little different than I said above.  There is no overflow
> problem and no problem with invalid values being produces, since the
> algorithm from ACM is careful to do everything with 32 bit signed
> integers without causing overflow.  The algorithm just doesn't produce
> values mod 2**32 as expected by all the functions.  It does what it
> claims to do -- it produces values mod (2**32 - 1).  The largest bug
> is that RAND_MAX is off by 1.  It is specified as the largest value
> returned by rand(), but in FreeBSD rand() never returns it unless
> USE_WEAK_SEEDING is confgured.  The values should be unifornly
> distributed on average beteen 0 and RAND_MAX,but that is impossible
> if RADND_MAX is never returned.  From libc/stdlib/srand.c:

Don't ever consider USE_WEAK_SEEDING defined - result is distributet
_very_ poorly and the code should be removed long time ago.

BTW, I don't understand well fixes you suggest. Is it to define RAND_MAX
as 0x7ffffffe ?

-- 
http://ache.vniz.net/
bitcoin:13fGiNutKNHcVSsgtGQ7bQ5kgUKgEQHn7N


More information about the svn-src-head mailing list