From f8b53a822ca9799742eaa119b0dfef2d1b1c9817 Mon Sep 17 00:00:00 2001 From: "Richard M. Stallman" Date: Thu, 28 Jul 1994 12:50:34 +0000 Subject: [PATCH] (random): Use rand differently, and distinguish BSD/USG. --- src/sysdep.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/sysdep.c b/src/sysdep.c index c6a3b4f7a82..dc5b7ee233f 100644 --- a/src/sysdep.c +++ b/src/sysdep.c @@ -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 } -- 2.39.5