Random number generator - why seed every time

前端 未结 7 2038
轻奢々
轻奢々 2020-12-06 04:58

I am relative new to c and c++. In java, the language I am used to program in, its very easy to implement random number generation. Just call the the static random-method fr

7条回答
  •  無奈伤痛
    2020-12-06 05:47

    What's usually called a random number generator is actually a pseudo-random number generator. This typically means that you can generate the same random sequence if you provide the "key" to that sequence, referred to as the "seed". This is very useful when you wish to test your algorithm that is based on randomization, and you need to ensure repeatable results.

    If you do not "seed" your Random number generator, it is seeded with some (usually based on system time) random number by default, and therefore produces the different sequence every time that you run your program.

提交回复
热议问题