diff options
author | Andrey A. Chernov <ache@FreeBSD.org> | 2003-02-03 10:22:12 +0000 |
---|---|---|
committer | Andrey A. Chernov <ache@FreeBSD.org> | 2003-02-03 10:22:12 +0000 |
commit | 2f5ef51de2995dce0f81042d954bb9c8f00e7d9f (patch) | |
tree | d0cfc71d1b2ec12652d4f2afb24ec1c659571650 /lib/libc/stdlib/rand.c | |
parent | f3cf900844d81871f07616d1f4c5cd9dd18db31b (diff) |
Notes
Diffstat (limited to 'lib/libc/stdlib/rand.c')
-rw-r--r-- | lib/libc/stdlib/rand.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/lib/libc/stdlib/rand.c b/lib/libc/stdlib/rand.c index 5b81da22b444..47bb36dcad9b 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 */ |