From owner-freebsd-current Mon Feb 3 3:46:37 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 7FD7C37B401 for ; Mon, 3 Feb 2003 03:46:32 -0800 (PST) Received: from nagual.pp.ru (pobrecita.freebsd.ru [194.87.13.42]) by mx1.FreeBSD.org (Postfix) with ESMTP id 6A95F43F85 for ; Mon, 3 Feb 2003 03:46:31 -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 h13BkUd6077631; Mon, 3 Feb 2003 14:46:30 +0300 (MSK) (envelope-from ache@pobrecita.freebsd.ru) Received: (from ache@localhost) by pobrecita.freebsd.ru (8.12.6/8.12.6/Submit) id h13BkTAH077630; Mon, 3 Feb 2003 14:46:29 +0300 (MSK) (envelope-from ache) Date: Mon, 3 Feb 2003 14:46:29 +0300 From: "Andrey A. Chernov" To: Kris Kennaway Cc: current@FreeBSD.ORG Subject: Final fix for correlation problem (was Re: rand() is broken) Message-ID: <20030203114629.GA77557@nagual.pp.ru> References: <20030202070644.GA9987@rot13.obsecurity.org> <20030202090422.GA59750@nagual.pp.ru> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-md5; protocol="application/pgp-signature"; boundary="bp/iNruPH9dso1Pn" Content-Disposition: inline In-Reply-To: <20030202090422.GA59750@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 --bp/iNruPH9dso1Pn Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable This is final fix for 1st value correlation problem. Somebody with=20 math statistic knowledge please run some test to be sure that NSHUFF is=20 good enough for this simple PRNG (i.e. not 100% good, but good for average= =20 quality PRNG we have). My simple test shown that 100 is enough, but I=20 am not PRNG math expert. Maybe increasing NSHUFF up too 2000 required. Similar patch is needed for random(3) TYPE_0 too, I'll produce it when we find good NSHUFF. --- stdlib/rand.c.bak Mon Feb 3 13:22:12 2003 +++ stdlib/rand.c Mon Feb 3 14:03:58 2003 @@ -51,6 +51,8 @@ #include #endif /* TEST */ =20 +#define NSHUFF 100 /* to drop seed -> 1st value correlation */ + static int do_rand(unsigned long *ctx) { @@ -108,7 +110,11 @@ srand(seed) u_int seed; { + int i; + next =3D seed; + for (i =3D 0; i < NSHUFF; i++) + (void)do_rand(&next); } =20 =20 @@ -137,7 +143,7 @@ unsigned long junk; =20 gettimeofday(&tv, NULL); - next =3D (getpid() << 16) ^ tv.tv_sec ^ tv.tv_usec ^ junk; + srand((getpid() << 16) ^ tv.tv_sec ^ tv.tv_usec ^ junk); } } =20 --=20 Andrey A. Chernov http://ache.pp.ru/ --bp/iNruPH9dso1Pn Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.0 (FreeBSD) iQCVAwUBPj5WleJgpPLZnQjrAQHqRgQAiH7mWI2K30s/m9dilOVcj5v62kVcPoW5 rADaGKbs44d3r6XVyFnlB32I4HNq74n8LhGQmxZTe0dHAF4Q4P3n0mLk4GgKyNEq nrAfJ0IE6y7YuEa71uACYq2G0DRPRITve/T80kWsDoTAHFA/Z/LG7OR2Q83UmrXz l6FSYPzmLk8= =juZn -----END PGP SIGNATURE----- --bp/iNruPH9dso1Pn-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message