diff options
Diffstat (limited to 'lib/libc')
-rw-r--r-- | lib/libc/stdlib/rand.c | 5 | ||||
-rw-r--r-- | lib/libc/stdlib/random.c | 5 |
2 files changed, 8 insertions, 2 deletions
diff --git a/lib/libc/stdlib/rand.c b/lib/libc/stdlib/rand.c index 5b81da2..47bb36d 100644 --- a/lib/libc/stdlib/rand.c +++ b/lib/libc/stdlib/rand.c @@ -72,10 +72,13 @@ do_rand(unsigned long *ctx) */ long hi, lo, x; + /* Can't be initialized with 0, so use another value. */ + if (*ctx == 0) + *ctx = 123459876; hi = *ctx / 127773; lo = *ctx % 127773; x = 16807 * lo - 2836 * hi; - if (x <= 0) + if (x < 0) x += 0x7fffffff; return ((*ctx = x) % ((u_long)RAND_MAX + 1)); #endif /* !USE_WEAK_SEEDING */ diff --git a/lib/libc/stdlib/random.c b/lib/libc/stdlib/random.c index b3a1e11..82af94c 100644 --- a/lib/libc/stdlib/random.c +++ b/lib/libc/stdlib/random.c @@ -236,10 +236,13 @@ static inline long good_rand (x) */ long hi, lo; + /* Can't be initialized with 0, so use another value. */ + if (x == 0) + x = 123459876; hi = x / 127773; lo = x % 127773; x = 16807 * lo - 2836 * hi; - if (x <= 0) + if (x < 0) x += 0x7fffffff; return (x); #endif /* !USE_WEAK_SEEDING */ |