What range of values does python's random seed take?

Viewed 224

Python's int type allows for very large values, but surely if I pass, for instance, 10**100000 into random.seed, it won't actually store that - does it just use a 32-bit integer internally?

1 Answers

If you pass as an int, 20.000 bits (from the right) will be used, in agreement with @joostblack, see Is there a maximum character limit to random seed?. The documentation states that the int is used directly, however, one should take a look at the source to see what it means.

If you want to use all the digits, you can split up the number yourself and provide it as a bytearray, in which case a hash function is applied. 1

Details of the int case

If you pass at as an int, python splits it up into 32-bit chunks 2, and set Mersenne Twister's internal state variables based on the list of these integers, by applying a non-linear function on the list 3. If you don't have enough values, e.g. if you gave a 64-bit int, another non-linear function will be used to initialize the internal state variables 4.

Related