diff options
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 | ||