]> 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:09:23 +0000 (22:09 -0700)
committerRaymond Hettinger <python@rcn.com>
Wed, 14 May 2014 05:09:23 +0000 (22:09 -0700)
to fully cover its state space.

Lib/random.py
Misc/NEWS

index 2f2f0915e2ef1fb293a814baaa082fb53c971b40..e89fae663a7b538bf2ed652f5aa299543e4cb081 100644 (file)
@@ -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
index 2bda7260c0c4c83ee85b39e8780c213cb98f9559..e028419feecb4c61efcad3cf2dc60604229e4c19 100644 (file)
--- 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().