On Tue, Feb 04, 2003 at 14:43:57 +0100, Dag-Erling Smorgrav wrote:

> I believe that's a feature.  All linear congruence generator have a
> fixed point.  0 is a far better fixed point than any other because it
> is more "obviously unsuited" (for some values of "obviously") as a
> seed value.  (but see below)

It is implementation details. rand() manpage says nothing about linear
congruence generator and not suppose special meaning of 0 which means that
application stuck at this point. We should not relay on that.

> > The next bug is that there is % RAND_MAX + 1, not % RAND_MAX.
> 
> No, using modulo 0x80000000 instead of modulo 0x7fffffff breaks the
> algorithm.  (but see below)

Yes, but manpage says about range from 0 to RAND_MAX inclusive. It means
that RAND_MAX clipping must be not part of algorithm and be applied only
at later stage.

> Changing RAND_MAX affects the algorithm in such a way that you should
> not do so without giving serious thought to revising the algorithm

Changing RAND_MAX should NOT affect algorithm at all, because RAND_MAX is 
not part of it.

> All that being said, adding 1 to *ctx before returning it (see patch)
> adresses both of your objections: a seed of 0 will not cause the LCG
> to get stuck, and the result of rand() will range between 0 and
> RAND_MAX inclusive.

Adding +1 you break algorithm formulae badly from math point of view,
something else then given formulae not allowed here. You can change 'a' 
parameter to anything you want, but not add something at the end.

-- 
Andrey A. Chernov
http://ache.pp.ru/

To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-current" in the body of the message

Reply via email to