KevinHall
February 27th, 2004, 06:50 PM
Q: What are good random number generators?
A: There are two common problems when using pseudo-random number generators (PRNGs):
The PRNG does not get seeded. Please see related FAQ (http://www.codeguru.com/forum/showthread.php?s=&threadid=284875) for discussion on this topic.
A poor PRNG is being used.
This FAQ addresses the second problem.
Often people use the C library function 'rand()' for random number generation. And quite often, the implementation for 'rand()' is not very good - the range of numbers is too small, the period before repetition is too small, and/or other problems.
Better PRNGs can be found in a variety of sources. The most popular is the "Mersenne Twister". The "Mersenne Twister" and other good PNRGs can be found in the Boost library (http://www.boost.org/libs/random/) and the GNU Scientific Library (http://www.gnu.org/software/gsl)).
Another good resource on random number generation is the book "Numerical Recipes in C". It contains a very good discussion on how one can create different distributions based on a uniform random deviate.
<br><br>
A: There are two common problems when using pseudo-random number generators (PRNGs):
The PRNG does not get seeded. Please see related FAQ (http://www.codeguru.com/forum/showthread.php?s=&threadid=284875) for discussion on this topic.
A poor PRNG is being used.
This FAQ addresses the second problem.
Often people use the C library function 'rand()' for random number generation. And quite often, the implementation for 'rand()' is not very good - the range of numbers is too small, the period before repetition is too small, and/or other problems.
Better PRNGs can be found in a variety of sources. The most popular is the "Mersenne Twister". The "Mersenne Twister" and other good PNRGs can be found in the Boost library (http://www.boost.org/libs/random/) and the GNU Scientific Library (http://www.gnu.org/software/gsl)).
Another good resource on random number generation is the book "Numerical Recipes in C". It contains a very good discussion on how one can create different distributions based on a uniform random deviate.
<br><br>