Read and respond to this message at:
I agree. For a quick and dirty random number, rand() is fine, but srand() it
first. Using the clock as a seed should be good, although most OSes have API
calls for better granularity, so more values. E.g. two programs started during
the same second will have the same sequence of random values, unless you use
a function that gives milliseconds (even then there is a chance...)
Anyway, I think the best solution for high-quality pseudo-random numbers is
to code your own, but this requires application of advanced discrete math,
probability, and statistics. Even among computer scientists, not everyone has
the skill to make a *good* pseudo-random number generator.
Dr. Knuth has a decent generator in his book, with code listed at his site.
I tweaked it a little bit and ran some tests, and it appears to work fairly
well, although it is slower and uses more static memory than the default rand().
A better solution would couple a generator such as Dr. Knuth's with a good entropy
source external to the computer. However, this gets way off topic for the MinGW
list and enters the realm of pure computer science...
Here is a link to Dr. Knuth's site. Look under the RANARRAY heading.
You are receiving this email because you elected to monitor this forum.
To stop monitoring this forum, login to SourceForge.net and visit: