Thursday, July 9, 2009

Quick C++ question about random number generator.?

If I seed the generator in the main file, can I just make a call to rand() in the implementation file? Will that work, or do I need to seed in in the implementation file? Of course I have #included the main file in the implementation file, by the way.


Thanks.

Quick C++ question about random number generator.?
You only need to seed the pseudo-random number generator once. It does not matter where you do it as long as both files have included in them cstdlib. You would also need to include time.h if you wanted to seed by the time.
Reply:You only need to seed rand once.


No comments:

Post a Comment