by ppcStudios » Sep 25, 2002 @ 4:09pm
Does GapiDraw happen to reseed the pseudorandom number generator with SRAND(val) on a periodic basis? The reason I'm asking is that unless I reseed prior to making a RAND( ) call, I get the same random number sequence back all the time. If I make the SRAND(GetTickCount()) call at the start of the application (this is using the CMyApplication framework), it has no effect on the return value of RAND( ). Here's an example :
Using the CMyApplication framework (I used the Simple sample program supplied with 1.04) place
DWORD dwSeed = GetTickCount();
srand(dwSeed);
just before "return simple.Run();" in WinMain( ).
This will seed the random number generator. You should only have to do this once at the start of an application. Multiple SRAND( ) calls are highly discouraged.
Now, in ProcessNextFrame( ), place this line at the top of the method
int r = (rand() % 10) + 1;
This will generate a random number from 1 to 10. Pretty simple stuff...
Launch the debugger and set a breakpoint on the rand call. Make note of the value that is returned and restart the debugger several times. You'll find that the random number is the same everytime.
Now, copy the srand code just before the rand line and run the debugger... random numbers as expected.
This says to me that srand is being reseeded with a value by GapiDraw every frame. I don't see this problem with a simple application outside the CMyApplication framework. Is there something I'm missing here?
Thanks for any insight on this problem... -- GR