Mail Archives: djgpp/1997/11/12/07:08:58
On 8 Nov 1997, Paul Derbyshire wrote:
> If rand() is ANSI but GCC's algorithm for rand() sucks, while its
> algorithm for random() is great, why not just use the better algorithm for
> both rand() and random(), while making sure the rand() arguments and
> return values have the same ranges and semantics as ANSI requires?
`random' wasn't written for DJGPP project. It was taken from the BSD
Unix library which is in public domain (and therefore free), but is
copyrighted by the Regents of the University of California. Somebody
with a good understanding in the legal aspects should look at the
copyright and tell whether the function's name can be changed. DJ should
be one person who should answer that.
> What exactly is the difference between the functions except the names?
Everything. `rand' is a simple linear-congruential generator. It
doesn't ``suck'', it's actually quite good and has a full 2^32 cycle,
but its low bits are not so ``random'', so "rand()%3" doesn't produce
a random 2-bit number.
`random' is much more complex and sophisticated, and produces much
more random low bits. I cannot explain here all its intricacies (this
issue took D. Knuth several hundreds of pages to explain), but you can
look into the code, which is commented to a large extent, and see for
yourself.
- Raw text -