Date: Tue, 4 Feb 2003 16:28:45 +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: <20030204132845.GA92674@nagual.pp.ru> In-Reply-To: <20030204131748.GA92510@nagual.pp.ru> References: <20030202070644.GA9987@rot13.obsecurity.org> <20030202090422.GA59750@nagual.pp.ru> <20030203002639.GB44914@HAL9000.homeunix.com> <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>
next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, Feb 04, 2003 at 16:17:48 +0300, Andrey A. Chernov wrote: > On Tue, Feb 04, 2003 at 16:10:06 +0300, Andrey A. Chernov wrote: > > On Tue, Feb 04, 2003 at 14:00:27 +0100, Dag-Erling Smorgrav wrote: > > > David Schultz <dschultz@uclink.Berkeley.EDU> writes: > > > > You can do better than the present generator with 32 bits of state. > > > > See the following page by Neal Wagner (not to be confused with David Wagner): > > > > http://www.cs.utsa.edu/~wagner/laws/rng.html > > > > > > The attached patch, based on one of the m/k pairs suggested on that > > > page, results in the following: > > > > I just think about 62089911 and 48271 too :-) > > > > There is one bug in your patch: 0 is still illegal, so my fix required. > > The next bug is that there is % RAND_MAX + 1, not % RAND_MAX. > > The next is not the bug but portability thing alowing different RAND_MAX: > you need to assign *ctx first and return it % RAND_MAX + 1 next, not > assign *ctx % RAND_MAX + 1 like you currently does. And the next bug is 32bit overflow there: tmp = *ctx * 62089911; must be tmp = (uint64_t) *ctx * 62089911; I'll produce working variant based on your patch... -- 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?20030204132845.GA92674>