Issues with seeding a pseudo-random number generator more than once?

前端 未结 4 1958
被撕碎了的回忆
被撕碎了的回忆 2021-01-12 21:57

I\'ve seen quite a few recommendations for not seeding pseudo-random number generators more than once per execution, but never accompanied by a thorough explanation. Of cour

4条回答
  •  情深已故
    2021-01-12 22:20

    If your seed is predictable, which it is here since you're just incrementing it, the output from rand() will also be predictable.

    It really depends on why you want to generate random numbers, and how "random" is an acceptable random for you. In your example, it may avoid duplicates in rapid succession, and that may be good enough for you. After all, what matters is that it runs.

    On almost every platform there is a better way to generate random numbers than rand().

提交回复
热议问题