Advertisement

Timing...to seed or not to seed (in each iteration)

Started by June 03, 2002 12:12 AM
1 comment, last by CoderX 22 years, 5 months ago
Should I seed the random generator inside the while loop or only once at the start of program? And why or why not?
++postcount;
Only once. Otherwise you might give it the same seed twice, and get the same result twice where you shouldn''t.

Advertisement
I agree. If you''re using srand(time(NULL)), then since time() changes only once per second, you''ll get the same set of random numbers more than you''d expect.

The only time that you should re-seed the generator is if you really want to generate the same set of numbers again.

This topic is closed to new replies.

Advertisement