[New-bugs-announce] [issue10025] random.seed not initialized as advertised
report at bugs.python.org
Tue Oct 5 01:33:06 CEST 2010
New submission from Tom Goddard <goddard at cgl.ucsf.edu>:
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(hash('1pov') + 2**32) # unsigned long cast
components: Library (Lib)
title: random.seed not initialized as advertised
versions: Python 2.7
Python tracker <report at bugs.python.org>
More information about the New-bugs-announce