On Sun, Feb 02, 2003 at 03:30:35PM +0300, Andrey A. Chernov wrote: > On Sun, Feb 02, 2003 at 13:26:21 +0300, Andrey A. Chernov wrote: > > > Workaround I find so far is something like that > > > > #define MASK 123459876 > > I found nothing better. Here is fix for 0 problem I plan to commit: > > --- stdlib/rand.c.old Sat Jan 4 20:39:19 2003 > +++ stdlib/rand.c Sun Feb 2 14:43:42 2003 > @@ -70,14 +70,18 @@ > * Park and Miller, Communications of the ACM, vol. 31, no. 10, > * October 1988, p. 1195. > */ > +#define SHIFT_MASK 123459876 > long hi, lo, x; > > - hi = *ctx / 127773; > - lo = *ctx % 127773; > + /* Can't be initialized with 0, so use shifting mask. */ > + x = *ctx ^ SHIFT_MASK; > + hi = x / 127773; > + lo = x % 127773; > x = 16807 * lo - 2836 * hi; > - if (x <= 0) > + if (x < 0) > x += 0x7fffffff; > - return ((*ctx = x) % ((u_long)RAND_MAX + 1)); > + *ctx = x ^ SHIFT_MASK; > + return (x % ((u_long)RAND_MAX + 1)); > #endif /* !USE_WEAK_SEEDING */ > }
I believe that this change just moves the "bad" seed to 123459876; after calling srand() with that seed, each call to rand() returns 0. Tim To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-current" in the body of the message