]> git.eshelyaron.com Git - emacs.git/commitdiff
(random): Use rand differently, and distinguish BSD/USG.
authorRichard M. Stallman <rms@gnu.org>
Thu, 28 Jul 1994 12:50:34 +0000 (12:50 +0000)
committerRichard M. Stallman <rms@gnu.org>
Thu, 28 Jul 1994 12:50:34 +0000 (12:50 +0000)
src/sysdep.c

index c6a3b4f7a82e228bb6186102dd876e0c5178f2a7..dc5b7ee233f153b658a583983df81a9a69fb19f6 100644 (file)
@@ -2612,8 +2612,15 @@ random ()
 #ifdef HAVE_RAND48
   return rand48 ();
 #else
-  /* Arrange to return a range centered on zero.  */
-  return (rand () << 15) + rand () - (1 << 29);
+/* The BSD rand returns numbers in the range of 0 to 2e31 - 1,
+   with unusable least significant bits.  The USG rand returns
+   numbers in the range of 0 to 2e15 - 1, all usable.  Let us
+   build a usable 30 bit number from either.  */
+#ifdef USG
+  return (rand () << 15) + rand ();
+#else
+  return (rand () & 0x3fff8000) + (rand () >> 16);
+#endif
 #endif
 }