Just curious how my seeding should work. |
Imagine a pearl necklace. A long one. Each pearl has a number. If you do read consecutive pearls, you will get a pseudo-random sequence. You have a finger on one pearl. You always do.
What does the rand() do? It does two things:
* Read number from pearl
* Move finger to next pearl
What does the srand() do? It moves the finger to a specific pearl.
You seed with time. Time has some resolution. Say one millisecond. How many times can your program call srand() within one millisecond? I bet many times.
Therefore, the time remains same on all those calls to srand(). Seed is same.
The srand() will move the finger to same pearl on all those calls.
All those rand() will read the same pearl, the same number.
I've heard anecdote on how rand() was "working fine" until a new computer was purchased. There was only one call to srand(), but the program was run multiple times. The new comp was so fast that the time was same on all runs.
Take a look at
http://www.cplusplus.com/reference/random/
Yes, they are more to type than the legacy rng, but supposedly more fun than
int rand() { return 42; }