# HG changeset patch # User Richard M. Stallman # Date 775603061 0 # Node ID e0c0247dca19ff4e7e8e0e0a8a03f3792e9a95af # Parent 7dca276b66d8fe3359eb28700fb1dac69847839e (Frandom): Handle LIMIT >= 40000000. diff -r 7dca276b66d8 -r e0c0247dca19 src/fns.c --- a/src/fns.c Sat Jul 30 21:11:00 1994 +0000 +++ b/src/fns.c Sat Jul 30 21:17:41 1994 +0000 @@ -64,17 +64,23 @@ srandom (getpid () + time (0)); if (XTYPE (limit) == Lisp_Int && XINT (limit) > 0) { - /* Try to take our random number from the higher bits of VAL, - not the lower, since (says Gentzel) the low bits of `random' - are less random than the higher ones. We do this by using the - quotient rather than the remainder. At the high end of the RNG - it's possible to get a quotient larger than limit; discarding - these values eliminates the bias that would otherwise appear - when using a large limit. */ - denominator = (unsigned long)0x40000000 / XFASTINT (limit); - do - val = (random () & 0x3fffffff) / denominator; - while (val >= limit); + if (XINT (limit) >= 0x40000000) + /* This case may occur on 64-bit machines. */ + val = random () % XINT (limit); + else + { + /* Try to take our random number from the higher bits of VAL, + not the lower, since (says Gentzel) the low bits of `random' + are less random than the higher ones. We do this by using the + quotient rather than the remainder. At the high end of the RNG + it's possible to get a quotient larger than limit; discarding + these values eliminates the bias that would otherwise appear + when using a large limit. */ + denominator = (unsigned long)0x40000000 / XFASTINT (limit); + do + val = (random () & 0x3fffffff) / denominator; + while (val >= limit); + } } else val = random ();