What alternatives are there to the C library's rand() and srand()?

The standard C library's rand() and srand() are often poor quality. You have many choices in trying to get better random numbers. First, you can try to extract the most random bits from the output of rand(), as described in C FAQ 13.16.

Second, you can use a different random number generator. Some older ones are recommended in the C FAQ. The Mersenne Twister is well recommended. Finally, if portability is paramount, you can try my own portable pseudo-random number generator: prng.c and prng.h.

Last updated 22 Jan 2004 23:13. Copyright © 2004 Ben Pfaff.
May be freely redistributed, but copyright notice must be retained.