This is final fix for 1st value correlation problem. Somebody with math statistic knowledge please run some test to be sure that NSHUFF is good enough for this simple PRNG (i.e. not 100% good, but good for average quality PRNG we have). My simple test shown that 100 is enough, but I 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 <stdio.h> #endif /* TEST */ +#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 = seed; + for (i = 0; i < NSHUFF; i++) + (void)do_rand(&next); } @@ -137,7 +143,7 @@ unsigned long junk; gettimeofday(&tv, NULL); - next = (getpid() << 16) ^ tv.tv_sec ^ tv.tv_usec ^ junk; + srand((getpid() << 16) ^ tv.tv_sec ^ tv.tv_usec ^ junk); } } -- Andrey A. Chernov http://ache.pp.ru/
msg51666/pgp00000.pgp
Description: PGP signature