tags:

views:

14

answers:

1

Is there a way to find how many times the C library function rand() has been called during an execution of a program? The program is written by myself thus its code can be edited.

I can find how many times rand() is called using Visual Studio debugger. However, I found that my program produces different random number sequence when running outside the debugger. Thus I want to investigate the invocation times outside the debugger as well.

Thanks.

+1  A: 

To produce the same set of random number just set the seed value to a predetermined value:

int main()
{
    srand(0); // The random number sequence should now be deterministic.
    // STUFF
}
Martin York
Yes, that works. That means different seeds are used inside and outside the debugger. Thanks.
Zhixiang Zhu