user288609 user288609 - 4 years ago 194
Python Question

random number generator in Python

I am using

to generate random number in a program. This random number generator is used multiple times in the code. At the beginning of the code, I initiate the seed with
. Is this the right practice? Thanks.

Answer Source

As documentation say, when you use random.seed you have two options:

random.seed() - seeds from current time or from an operating system specific randomness source if available

random.seed(a) - hash(a) is used instead as seed

Using time as seed is better practice if you want to have different numbers between two instances of your program, but for sure is much harder to debug.

Using hardcoded number as seed makes your random numbers much more predictable.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download