Good practice for seeding rand()?

We all know how rand() works. Seed it once, and it produces a string of pseudo-random numbers.

If my program needs a couple thousand random inputs, can I expect rand() to reliably produce these numbers with reasonable randomness with just one seed? Or should I reseed it at some point?

Does the answer change if I need a couple million random numbers?
The only problem I can think of is if you generate more numbers than rand()'s period so that the sequence of random numbers will then repeat. A couple of million numbers shouldn't be a problem unless your implementation of rand() is crap. If you want something better you could try another random generator like Mersenne twister that has very long period of 219937−1. Mersenne twister was added to C++ in C++11.
Last edited on
Topic archived. No new replies allowed.