How to get current seed from C++ rand()?

前端 未结 8 741
名媛妹妹
名媛妹妹 2020-12-31 01:49

I generate a few thousand object in my program based on the C++ rand() function. Keeping them in the memory would be exhaustive. Is there a way to copy the CURRENT

8条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-31 02:19

    You could try saving the value that you used to seed right before (or after) the srand.

    So, for example:

    int seed = time(NULL);
    srand(time(NULL));
    
    cout << seed << endl;
    cout << time(NULL);
    

    The two values should be the same.

提交回复
热议问题