How often should I call srand() in a C++ application?

后端 未结 4 1932
轮回少年
轮回少年 2020-11-30 14:08

I have a C++ application which calls rand() in various places. Do I need to initialize srand() regularly to ensure that rand() is reasonably random, or is it en

4条回答
  •  独厮守ぢ
    2020-11-30 14:32

    No just calling once is fine. Use the seed value to make the random sequence the same on each execution. This could be useful in making (for example) a game's behaviour deterministic when you replay it for debugging.

提交回复
热议问题