From owner-freebsd-current Sun Feb 2 2:26:27 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 604F737B405 for ; Sun, 2 Feb 2003 02:26:25 -0800 (PST) Received: from nagual.pp.ru (pobrecita.freebsd.ru [194.87.13.42]) by mx1.FreeBSD.org (Postfix) with ESMTP id ED5B243F9B for ; Sun, 2 Feb 2003 02:26:23 -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 h12AQMd6060932; Sun, 2 Feb 2003 13:26:22 +0300 (MSK) (envelope-from ache@pobrecita.freebsd.ru) Received: (from ache@localhost) by pobrecita.freebsd.ru (8.12.6/8.12.6/Submit) id h12AQLFF060931; Sun, 2 Feb 2003 13:26:21 +0300 (MSK) (envelope-from ache) Date: Sun, 2 Feb 2003 13:26:21 +0300 From: "Andrey A. Chernov" To: Kris Kennaway Cc: current@FreeBSD.org Subject: Re: rand() is broken Message-ID: <20030202102621.GA60900@nagual.pp.ru> References: <20030202070644.GA9987@rot13.obsecurity.org> <20030202090422.GA59750@nagual.pp.ru> <20030202091106.GA72723@rot13.obsecurity.org> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-md5; protocol="application/pgp-signature"; boundary="ibTvN161/egqYuK8" Content-Disposition: inline In-Reply-To: <20030202091106.GA72723@rot13.obsecurity.org> 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 --ibTvN161/egqYuK8 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sun, Feb 02, 2003 at 01:11:06 -0800, Kris Kennaway wrote: >=20 > Another problem (noticed by tjr) is that once the sequence hits '0' it > jumps to INT_MAX and stays there forever. For example, seeding with > srand(0) produces nothing but INT_MAX from rand(). >=20 > It looks like a lot more validation of this PRNG is needed. As I see searching through various sources, this is not simple overlook but fundamental feature of this formulae - it can't be initialized with zero and BSD developers try to deal with that fact by simple adding of INT_MAX in zero case (which is not in the original formulae), but gain nothing this way. Workaround I find so far is something like that #define MASK 123459876 seed ^=3D MASK; =2E.. calculate value ... seed ^=3D MASK; Which just add another magick value, but fix zero.=20 I am still searching... --=20 Andrey A. Chernov http://ache.pp.ru/ --ibTvN161/egqYuK8 Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.0 (FreeBSD) iQCVAwUBPjzyTeJgpPLZnQjrAQGBwwP5Ae/dZqhYgeqAH3ZUkOHkObIPmXhmVZPl 0091968Inv2g3RAZj/qw2TaxjDZSAllUi2PjRhfqy25T2qOPV3v4EgoFHYMzQywP reHIw7p0jNZ2m7HBRJhWhx96kCQNwJsMp04klcNgbz8gdmGZJITgt6fjEXLyb3Qy 47LaVPkvys8= =AukL -----END PGP SIGNATURE----- --ibTvN161/egqYuK8-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message