In 64 bit Python 2.7.6 this is True, however in 32 bit Python 2.7.3 it is False:
random.Random(hash("a")).random() == random.Random("a").random()
So how does Python 2.7.3 hash strings used to seed random number generators?
it's because on 32bit hash("a")
is a negative number (because of platform long type size) and the random modules behaves differently.
The random module seed() function:
PyNumber_Absolute()
that is abs()
PyLong_FromUnsignedLong((unsigned long)hash)
sign bit truncation and abs give different result
e.g.:
abs(-10) = 10
((unsigned long) -10) = 4294967286
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With