From owner-freebsd-current Tue Feb 4 6:28:59 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 013FE37B405 for ; Tue, 4 Feb 2003 06:28:58 -0800 (PST) Received: from nagual.pp.ru (pobrecita.freebsd.ru [194.87.13.42]) by mx1.FreeBSD.org (Postfix) with ESMTP id 8A30A43E4A for ; Tue, 4 Feb 2003 06:28:56 -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 h14EStd6093461; Tue, 4 Feb 2003 17:28:55 +0300 (MSK) (envelope-from ache@pobrecita.freebsd.ru) Received: (from ache@localhost) by pobrecita.freebsd.ru (8.12.6/8.12.6/Submit) id h14ESsvW093460; Tue, 4 Feb 2003 17:28:54 +0300 (MSK) (envelope-from ache) Date: Tue, 4 Feb 2003 17:28:54 +0300 From: "Andrey A. Chernov" To: Dag-Erling Smorgrav Cc: David Schultz , Kris Kennaway , current@FreeBSD.ORG Subject: Re: rand() is broken Message-ID: <20030204142854.GA93413@nagual.pp.ru> References: <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> <20030204140052.GA93115@nagual.pp.ru> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 15:23:28 +0100, Dag-Erling Smorgrav wrote: > "Andrey A. Chernov" 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