Date: Sun, 2 Feb 2003 13:26:21 +0300 From: "Andrey A. Chernov" <ache@nagual.pp.ru> To: Kris Kennaway <kris@obsecurity.org> Cc: current@FreeBSD.org Subject: Re: rand() is broken Message-ID: <20030202102621.GA60900@nagual.pp.ru> In-Reply-To: <20030202091106.GA72723@rot13.obsecurity.org> References: <20030202070644.GA9987@rot13.obsecurity.org> <20030202090422.GA59750@nagual.pp.ru> <20030202091106.GA72723@rot13.obsecurity.org>
next in thread | previous in thread | raw e-mail | index | archive | help
--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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20030202102621.GA60900>