]> git.eshelyaron.com Git - emacs.git/commitdiff
(Frandom): Handle LIMIT >= 40000000.
authorRichard M. Stallman <rms@gnu.org>
Sat, 30 Jul 1994 21:17:41 +0000 (21:17 +0000)
committerRichard M. Stallman <rms@gnu.org>
Sat, 30 Jul 1994 21:17:41 +0000 (21:17 +0000)
src/fns.c

index c91710b7c10b5b3cda23073583384276cd4bb1a9..b65f3f203f7877bd1f39d0a617b73f4bb81a8db7 100644 (file)
--- a/src/fns.c
+++ b/src/fns.c
@@ -64,17 +64,23 @@ With argument t, set the random number seed from the current time and pid.")
     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 ();