changeset 8368:0c30bec316c6

(random): Use rand differently, and distinguish BSD/USG.
author Richard M. Stallman <rms@gnu.org>
date Thu, 28 Jul 1994 12:50:34 +0000
parents 31ceccb9982d
children c10b35194993
files src/sysdep.c
diffstat 1 files changed, 9 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/sysdep.c	Thu Jul 28 12:46:16 1994 +0000
+++ b/src/sysdep.c	Thu Jul 28 12:50:34 1994 +0000
@@ -2612,8 +2612,15 @@
 #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
 }