Date: Tue, 4 Feb 2003 17:28:54 +0300 From: "Andrey A. Chernov" <ache@nagual.pp.ru> To: Dag-Erling Smorgrav <des@ofug.org> Cc: David Schultz <dschultz@uclink.Berkeley.EDU>, Kris Kennaway <kris@obsecurity.org>, current@FreeBSD.ORG Subject: Re: rand() is broken Message-ID: <20030204142854.GA93413@nagual.pp.ru> In-Reply-To: <xzpfzr4untr.fsf@flood.ping.uio.no> References: <20030203100002.GA73386@nagual.pp.ru> <20030204054020.GA2447@HAL9000.homeunix.com> <20030204094659.GA87303@nagual.pp.ru> <20030204115237.GA6483@HAL9000.homeunix.com> <xzpfzr4b3pw.fsf@flood.ping.uio.no> <20030204131006.GB92301@nagual.pp.ru> <20030204131748.GA92510@nagual.pp.ru> <xzpwukgupnm.fsf@flood.ping.uio.no> <20030204140052.GA93115@nagual.pp.ru> <xzpfzr4untr.fsf@flood.ping.uio.no>
next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, Feb 04, 2003 at 15:23:28 +0100, Dag-Erling Smorgrav wrote: > "Andrey A. Chernov" <ache@nagual.pp.ru> writes: > > On Tue, Feb 04, 2003 at 14:43:57 +0100, Dag-Erling Smorgrav wrote: > > > 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. > > Do the math - adding 1 after the modulo operation is equivalent to > setting a == k. Repeated k may affect distribution. Better variant will be with a != k. -- Andrey A. Chernov http://ache.pp.ru/ To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20030204142854.GA93413>