开发者

How to investigate the times a library function like rand() is invoked in C

开发者 https://www.devze.com 2023-01-15 22:50 出处:网络
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.

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 debug开发者_运维技巧ger as well.

Thanks.


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
}
0

精彩评论

暂无评论...
验证码 换一张
取 消