[Python-checkins] cpython (2.7): Issue #21470: Do a better job seeding the random number generator
raymond.hettinger
python-checkins at python.org
Wed May 14 07:09:44 CEST 2014
http://hg.python.org/cpython/rev/7b5265752942
changeset: 90691:7b5265752942
branch: 2.7
parent: 90682:d4fd55278cec
user: Raymond Hettinger <python at rcn.com>
date: Tue May 13 22:09:23 2014 -0700
summary:
Issue #21470: Do a better job seeding the random number generator
to fully cover its state space.
files:
Lib/random.py | 4 +++-
Misc/NEWS | 3 +++
2 files changed, 6 insertions(+), 1 deletions(-)
diff --git a/Lib/random.py b/Lib/random.py
--- a/Lib/random.py
+++ b/Lib/random.py
@@ -108,7 +108,9 @@
if a is None:
try:
- a = long(_hexlify(_urandom(32)), 16)
+ # Seed with enough bytes to span the 19937 bit
+ # state space for the Mersenne Twister
+ a = long(_hexlify(_urandom(2500)), 16)
except NotImplementedError:
import time
a = long(time.time() * 256) # use fractional seconds
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -52,6 +52,9 @@
- Issue #21306: Backport hmac.compare_digest from Python 3. This is part of PEP
466.
+- Issue #21470: Do a better job seeding the random number generator by
+ using enough bytes to span the full state space of the Mersenne Twister.
+
- Issue #21469: Reduced the risk of false positives in robotparser by
checking to make sure that robots.txt has been read or does not exist
prior to returning True in can_fetch().
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list