What is the initial value to use with random.seed ()?

A fairly simple question:

I am using a random python module to generate random integers. I want to know what is the suggested value to use with the random.seed () function? I am currently giving this the default current time, but this is not ideal. It seems like the string literal constant (similar to password) would not be ideal / strong either.

Suggestions?

Thanks, -L


UPDATE:

The reason I generate random integers is to create test data. Numbers should not be reproduced.

+4
source share
5 answers

According to the documentation for random.seed :

If x is omitted or No , the current system time is used; The current system time is also used to initialize the generator when the module is first imported. If sources of randomness are provided by the operating system, they are used instead of system time (see the os.urandom() Function for more information on availability).

If you don’t pass something to the seed, it will try to use random information sources provided by the operating system, rather than time, which is always better. This saves you a bit of work and is about as good as it will be. Regarding accessibility, the docs for os.urandom tell us:

On a UNIX-like system, this will request / dev / urandom, while on Windows it will use CryptGenRandom.

Cross-platform random seeds are a big win here; you can safely omit the seed and hope that it will be random enough on almost every platform on which you will use Python. Even if Python returns to a point in time, perhaps only a millisecond window (or less) to guess the seed. I do not think that in any case you will encounter any problem using the current time - even then it will be only a reserve.

+13
source

In most cases, using the current time is good enough. Sometimes you need to use a fixed number to generate pseudo random numbers for comparison purposes.

+5
source

Setting the seed for repeatability, not security. In any case, you make the system less secure with a fixed seed than a constant change.

+3
source

Perhaps this is not a problem in your case, but the problem of using system time as a seed is that someone who knows when your system was started can guess your seed (through the trial version) by seeing a few numbers from sequence. for example, do not use system time as a seed for your online poker game

+1
source

If you arbitrarily use test data, I would suggest that reproducibility be important.

Just think of a use case: for dataset X, you will get some strange behavior (like crashing). It turns out that dataset X shows some function that is not so obvious from other datasets Y and Z and reveals an error that avoided your test sets. Now knowing the seed is useful so that you can accurately reproduce the error, and you can correct it.

0
source

All Articles