summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2014-05-14 05:09:23 (GMT)
committerRaymond Hettinger <python@rcn.com>2014-05-14 05:09:23 (GMT)
commitddb39e799d65748c5ea42c344170befc90af9e64 (patch)
tree7d9b53921e001a17db74e7ed8ba30d7c87e8cd49
parenta5413c499702a74fdc50e4bc8e7e6a480856a1f9 (diff)
downloadcpython-ddb39e799d65748c5ea42c344170befc90af9e64.zip
cpython-ddb39e799d65748c5ea42c344170befc90af9e64.tar.gz
cpython-ddb39e799d65748c5ea42c344170befc90af9e64.tar.bz2
Issue #21470: Do a better job seeding the random number generator
to fully cover its state space.
-rw-r--r--Lib/random.py4
-rw-r--r--Misc/NEWS3
2 files changed, 6 insertions, 1 deletions
diff --git a/Lib/random.py b/Lib/random.py
index 2f2f091..e89fae6 100644
--- a/Lib/random.py
+++ b/Lib/random.py
@@ -108,7 +108,9 @@ class Random(_random.Random):
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
index 2bda726..e028419 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -52,6 +52,9 @@ Library
- 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().