From owner-freebsd-current Sun Feb 2 6: 2:28 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 1ADD437B405; Sun, 2 Feb 2003 06:02:27 -0800 (PST) Received: from nagual.pp.ru (pobrecita.freebsd.ru [194.87.13.42]) by mx1.FreeBSD.org (Postfix) with ESMTP id 95A4A43F9B; Sun, 2 Feb 2003 06:02:24 -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 h12E2Nd6063897; Sun, 2 Feb 2003 17:02:23 +0300 (MSK) (envelope-from ache@pobrecita.freebsd.ru) Received: (from ache@localhost) by pobrecita.freebsd.ru (8.12.6/8.12.6/Submit) id h12E2NIf063896; Sun, 2 Feb 2003 17:02:23 +0300 (MSK) (envelope-from ache) Date: Sun, 2 Feb 2003 17:02:23 +0300 From: "Andrey A. Chernov" To: Tim Robbins Cc: Kris Kennaway , current@FreeBSD.ORG Subject: Re: rand() is broken Message-ID: <20030202140223.GA63836@nagual.pp.ru> References: <20030202070644.GA9987@rot13.obsecurity.org> <20030202090422.GA59750@nagual.pp.ru> <20030202091106.GA72723@rot13.obsecurity.org> <20030202102621.GA60900@nagual.pp.ru> <20030202123035.GB62977@nagual.pp.ru> <20030203001735.A30440@dilbert.robbins.dropbear.id.au> <20030202134225.GA63673@nagual.pp.ru> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20030202134225.GA63673@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 Sun, Feb 02, 2003 at 16:42:25 +0300, Andrey A. Chernov wrote: > On Mon, Feb 03, 2003 at 00:17:35 +1100, Tim Robbins wrote: > > > > I believe that this change just moves the "bad" seed to 123459876; after > > calling srand() with that seed, each call to rand() returns 0. > > Yes. Nothing better is possible for this formulae and this is documented > in algorithm, some value must be excluded. Excluding 0 is bad only because > srand(0) is commonly used and srand(123459876) is not. This workaround can be improved more, to make generator not stuck ever with 123459876 by simple way: if (seed == 123459876) seed = 123459877; It can be done even with original variant using more simpler patch: if (seed == 0) seed = 123459876; I'll produce and send it a bit later. -- 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