Micah Cowan said:
I never said you recommended any such thing. I said that your code did
so. This is apparently wrong, as it is actually Sinan's code I'm
referring to, after checking up on it. So yes, to some degree, I'm
getting you confused.
Ok. What you wrote above could reasonably be interpreted to imply
that I recommended calling srand() before every rand(), and in fact
that's how I interpreted it. I thought the "as you've done" referred
to *recommending* calling srand() rather than to calling srand().
Thanks for the clarification.
[...]
(You meant srand() instead of the first rand())
Yes, acknowledged elsethread.
Calling srand() more than once will not repeat the same sequence of
pseudo-random numbers, unless you stupidly provide it with the same
input as the last time. I'm fairly certain Rod intended that you call
it each time with a time-based value.
If you *want* to repeat the same sequence, calling srand with the same
argument is exactly what you want to do. (For example, you might want
to produce two identical shuffles of a deck of cards, or otherwise
allow a user to re-play the same game of whatever.)
I'm not convinced that Rod has been consistent. I suggest we wait for
him to clarify what he meant.
I don't see how that follows.
It doesn't follow as a matter of rigorous deductive reasoning, but it
seems to me to be a reasonable common-sense inference. Any decent
pseudo-random number generator is going to be designed to work best
when it's allowed to generate a sequence from a starting seed without
interference. If you try to second-guess the algorithm by arbitrarily
perturbing it with additional calls to srand(), there is no reason to
think that the result is going to be any better (whatever "better"
means). If you *know* that re-seeding the algorithm will generate
better results, that implies, I think, that the algorithm is
defective, and you should just use a better one (many are freely
available). A re-seeding scheme that improves one RNG is unlikely to
improve another RNG, so any code that does something like this is
going to be gratuitously non-portable anyway. Using a different RNG
doesn't even sacrifice portability; numerous RNGs are available in
portable C code.
Rod Pemberton seems to disagree with this (though I haven't been able
to figure out what he's really trying to say). He's free to explain
his reasoning if he wants to. He's also free to drop the whole thing.