[Python-checkins] cpython (3.4): Issue #21470: Do a better job seeding the random number generator
raymond.hettinger
python-checkins at python.org
Wed May 14 07:21:36 CEST 2014
http://hg.python.org/cpython/rev/c203df907092
changeset: 90692:c203df907092
branch: 3.4
parent: 90689:16d26391ec36
user: Raymond Hettinger <python at rcn.com>
date: Tue May 13 22:13:40 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
@@ -105,7 +105,9 @@
if a is None:
try:
- a = int.from_bytes(_urandom(32), 'big')
+ # Seed with enough bytes to span the 19937 bit
+ # state space for the Mersenne Twister
+ a = int.from_bytes(_urandom(2500), 'big')
except NotImplementedError:
import time
a = int(time.time() * 256) # use fractional seconds
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -26,6 +26,9 @@
- Issue #21396: Fix TextIOWrapper(..., write_through=True) to not force a
flush() on the underlying binary stream. Patch by akira.
+- 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 #21398: Fix an unicode error in the pydoc pager when the documentation
contains characters not encodable to the stdout encoding.
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list