Re: RAND_MAX broken

2013-07-02 Thread Bruce Evans
On Wed, 3 Jul 2013, Andrey Chernov wrote: On 02.07.2013 20:33, Bruce Evans wrote: I checked the values returned by rand(). The ACM part works as intended, so it never returns RAND_MAX. It also never returns 0. So the distribution of values in the documented range [0, RAND_MAX] is very non-un

Re: RAND_MAX broken

2013-07-02 Thread Andrey Chernov
On 02.07.2013 20:33, Bruce Evans wrote: > I checked the values returned by rand(). The ACM part works as > intended, so it never returns RAND_MAX. It also never returns 0. So > the distribution of values in the documented range [0, RAND_MAX] is > very non-uniform. It is uniform in [1, RAND_MAX

Re: RAND_MAX broken

2013-07-02 Thread Bruce Evans
On Tue, 2 Jul 2013, Andrey Chernov wrote: 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 integ

Re: RAND_MAX broken

2013-07-02 Thread Andrey Chernov
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 alg

RAND_MAX broken (was: Re: svn commit: r252484 - head/sys/ufs/ffs)

2013-07-02 Thread Bruce Evans
On Tue, 2 Jul 2013, Bruce Evans wrote: ... Also, random(9) is internally broken on 64-bit arches. It shouldn't exist. It is not random() at all, but just rand() with the clamp to RAND_MAX removed. Its linear congruential generator is suboptimal for 64 bits, and other parts of its algorithm ar