]> granicus.if.org Git - python/commitdiff
Issue #21470: Do a better job seeding the random number generator
authorRaymond Hettinger <python@rcn.com>
Wed, 14 May 2014 05:13:40 +0000 (22:13 -0700)
committerRaymond Hettinger <python@rcn.com>
Wed, 14 May 2014 05:13:40 +0000 (22:13 -0700)
to fully cover its state space.

Lib/random.py
Misc/NEWS

index 808175ab4a100ea6ea0775ddf6d7ff0a098c0a05..174e755a0297b9379efad7d45f2063d803ee6340 100644 (file)
@@ -105,7 +105,9 @@ class Random(_random.Random):
 
         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
index f85155e0bc3a5e013c057bda610c88bb0d248de4..eff6573d94705a3fca28c9690066d70c7a6648de 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -26,6 +26,9 @@ Library
 - 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.