[issue27706] Random.seed, whose purpose is purportedly determinism, behaves non-deterministically with strings due to hash randomization

Terry J. Reedy report at bugs.python.org
Sun Aug 14 23:44:16 EDT 2016


Terry J. Reedy added the comment:

I agree with the value of a Reproducibility guarantee.  (The new section appears to have been added -- by Raymond -- in 3.2.)  For instance, people posting play-through videos using reproducible random maps typically post the 'seed' and I have seen memorable phrases rather than ints used.  I can imagine myself publishing seeds in other contexts.

In 3.2, seed gained a 2nd parameter -- 'version'.  "With version 2 (the default), a str, bytes, or bytearray object gets converted to an int and all of its bits are used."  For this case, hashing is not an issue. But 'conversion to int' is. Did it change with the introduction of FSR in 3.3?  It certainly should be frozen now, and the fact noted in the code.

For other non-int objects, a hashable is required.  (I expect anything other than int or string-like to be rare.) The doc does not say so (it should), but the dosctring does and experiment with [] confirms.

"With version 1, the hash() of a is used instead."

For hashed objects, whether version is 1 or 2, I guess the best we can do is to restore the fixed hash once used.

For a fixed sequence of outputs, both seed and rng have to be fixed.  2.7 still has WichmannHill for this reason.  It is gone in 3.x.  It the rng is significantly changed (different sequence for the same seed), I believe the seed version should be changed also.

----------
nosy: +terry.reedy

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue27706>
_______________________________________


More information about the Python-bugs-list mailing list