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

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

    The random number generation classes in C++11 support operator<< to store their state (mostly the seed) and operator>> to read it back in. So, basically, before you create your objects, save the state, then when you need to re-generate same sequence, read the state back in, and off you go.

提交回复
热议问题