From owner-freebsd-current Tue Feb 4 5:28:49 2003 Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 436B837B401 for ; Tue, 4 Feb 2003 05:28:48 -0800 (PST) Received: from nagual.pp.ru (pobrecita.freebsd.ru [194.87.13.42]) by mx1.FreeBSD.org (Postfix) with ESMTP id 1B3CF43F75 for ; Tue, 4 Feb 2003 05:28:47 -0800 (PST) (envelope-from ache@pobrecita.freebsd.ru) Received: from pobrecita.freebsd.ru (ache@localhost [127.0.0.1]) by nagual.pp.ru (8.12.6/8.12.6) with ESMTP id h14DSjd6092696; Tue, 4 Feb 2003 16:28:45 +0300 (MSK) (envelope-from ache@pobrecita.freebsd.ru) Received: (from ache@localhost) by pobrecita.freebsd.ru (8.12.6/8.12.6/Submit) id h14DSjDa092695; Tue, 4 Feb 2003 16:28:45 +0300 (MSK) (envelope-from ache) Date: Tue, 4 Feb 2003 16:28:45 +0300 From: "Andrey A. Chernov" To: Dag-Erling Smorgrav Cc: David Schultz , Kris Kennaway , current@FreeBSD.ORG Subject: Re: rand() is broken Message-ID: <20030204132845.GA92674@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> <20030204131006.GB92301@nagual.pp.ru> <20030204131748.GA92510@nagual.pp.ru> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20030204131748.GA92510@nagual.pp.ru> User-Agent: Mutt/1.5.1i Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG 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 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