Issue 10025: random.seed not initialized as advertised (original) (raw)

Issue10025

Created on 2010-10-04 23:33 by goddard, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (4)
msg117988 - (view) Author: Tom Goddard (goddard) Date: 2010-10-04 23:33
In Python 2.7, random.seed() with a string argument is documented as being equivalent to random.seed() with argument equal to the hash of the string argument. This is not the actual behavior. Reading the _random C code reveals it in fact casts the signed hash value to unsigned long. This also appears to be the situation with Python 2.5.2. Rather than fix this in 2.7.1 it seems preferable to just correct the documentation in 2.7.1 to preserve backward compatibility. Bug #7889 has already addressed this problem in Python 3.2 by eliminating the use of hash() for non-integer random.seed() arguments. I encountered this problem while trying to produce identical sequences of random numbers on 64-bit architectures as on 32-bit architectures. Here is a demonstration of the bug in Python 2.7, 32-bit. random.seed('1pov') random.uniform(0,1) 0.713827305919223 random.seed(hash('1pov')) random.uniform(0,1) 0.40934677883730686 hash('1pov') -747753952 random.seed(hash('1pov') + 2**32) # unsigned long cast random.uniform(0,1) 0.713827305919223
msg118233 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2010-10-08 23:07
3.1 has the same problem (and the same results as above) Assuming behavior is not changed, please suggest a specific rewording that you would be happy with and that is not too verbose.
msg118238 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2010-10-09 00:01
Perhaps replace equivalent with "based on" or some such. This is a very minor nit and likely of interest to no one except the OP.
msg120076 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2010-10-31 18:16
Removed the inaccurate description. See r86053.
History
Date User Action Args
2022-04-11 14:57:07 admin set github: 54234
2010-10-31 18:16:03 rhettinger set status: open -> closedresolution: fixedmessages: +
2010-10-09 00:01:31 rhettinger set priority: normal -> lowmessages: +
2010-10-08 23:07:13 terry.reedy set versions: + Python 3.1nosy: + terry.reedymessages: + components: + Documentationstage: needs patch
2010-10-05 02:32:40 rhettinger set assignee: rhettinger
2010-10-05 00:01:38 r.david.murray set nosy: + rhettinger
2010-10-04 23:33:05 goddard create