NetBSD-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

The simple algorithm on rand(3)



Hi!

Using zsh's $RANDOM I discovered that it always generated one odd
number, and then, an even number.  It just feeds srand() with the last
generated number from rand().

(I was trying to generate a stream of random 0 and 1 but just got
regular 01010101 sequences...)

After investigating, I found that the simple algorithm under
src/lib/libc/stdlib/rand.c has exactly this behaviour.  random(3) warns
about its lack of randomness.

I was thinking about file a PR, but decided to ask you first if you want
to keep this algorithm.  Should I report a bug to tell zsh guys and
other applications to use random(3) instead?

Thanks.

-- 
Silas


Home | Main Index | Thread Index | Old Index