diff options
| author | Richard M. Stallman | 1994-07-28 12:50:34 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1994-07-28 12:50:34 +0000 |
| commit | f8b53a822ca9799742eaa119b0dfef2d1b1c9817 (patch) | |
| tree | f8ad6a0c1b88c7d227c16c0246482fbd8dbb9f5c /src | |
| parent | 8ee9ba64c157cf53bd3662f2232522b78caee354 (diff) | |
| download | emacs-f8b53a822ca9799742eaa119b0dfef2d1b1c9817.tar.gz emacs-f8b53a822ca9799742eaa119b0dfef2d1b1c9817.zip | |
(random): Use rand differently, and distinguish BSD/USG.
Diffstat (limited to 'src')
| -rw-r--r-- | src/sysdep.c | 11 |
1 files 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 () | |||
| 2612 | #ifdef HAVE_RAND48 | 2612 | #ifdef HAVE_RAND48 |
| 2613 | return rand48 (); | 2613 | return rand48 (); |
| 2614 | #else | 2614 | #else |
| 2615 | /* Arrange to return a range centered on zero. */ | 2615 | /* The BSD rand returns numbers in the range of 0 to 2e31 - 1, |
| 2616 | return (rand () << 15) + rand () - (1 << 29); | 2616 | with unusable least significant bits. The USG rand returns |
| 2617 | numbers in the range of 0 to 2e15 - 1, all usable. Let us | ||
| 2618 | build a usable 30 bit number from either. */ | ||
| 2619 | #ifdef USG | ||
| 2620 | return (rand () << 15) + rand (); | ||
| 2621 | #else | ||
| 2622 | return (rand () & 0x3fff8000) + (rand () >> 16); | ||
| 2623 | #endif | ||
| 2617 | #endif | 2624 | #endif |
| 2618 | } | 2625 | } |
| 2619 | 2626 | ||