Skip site navigation (1)Skip section navigation (2)
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>

index | next in thread | previous in thread | raw e-mail

[-- Attachment #1 --]
On Sun, Feb 02, 2003 at 01:11:06 -0800, Kris Kennaway wrote:
> 
> 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().
> 
> 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 ^= MASK;
... calculate value ...
seed ^= MASK;

Which just add another magick value, but fix zero. 
I am still searching...

-- 
Andrey A. Chernov
http://ache.pp.ru/

[-- Attachment #2 --]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.0 (FreeBSD)

iQCVAwUBPjzyTeJgpPLZnQjrAQGBwwP5Ae/dZqhYgeqAH3ZUkOHkObIPmXhmVZPl
0091968Inv2g3RAZj/qw2TaxjDZSAllUi2PjRhfqy25T2qOPV3v4EgoFHYMzQywP
reHIw7p0jNZ2m7HBRJhWhx96kCQNwJsMp04klcNgbz8gdmGZJITgt6fjEXLyb3Qy
47LaVPkvys8=
=AukL
-----END PGP SIGNATURE-----
help

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20030202102621.GA60900>