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

前端 未结 8 737
名媛妹妹
名媛妹妹 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:28

    I would recommend you to use the Mersenne Twister Pseudo-Random Number Generator. It is fast and offer very good random numbers. You can seed the generator in the constructor of the class very simply by

    unsigned long rSeed = 10;
    MTRand myRandGen(rSeed);
    

    Then you just need to store somewhere the seeds you used to generate the sequences...

提交回复
热议问题