]> git.ipfire.org Git - thirdparty/dnspython.git/commitdiff
Use random.SystemRandom when available.
authorBob Halley <halley@dnspython.org>
Thu, 4 Aug 2016 13:03:31 +0000 (06:03 -0700)
committerBob Halley <halley@dnspython.org>
Thu, 4 Aug 2016 13:03:31 +0000 (06:03 -0700)
dns/entropy.py

index 22114579af48a7f6ff03f329e6d9b677f7a13a12..7a2d87d10ac6d32d15983f3e830e177ddc5fb14b 100644 (file)
@@ -14,6 +14,7 @@
 # OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
 import os
+import random
 import time
 from ._compat import long, binary_type
 try:
@@ -122,10 +123,19 @@ class EntropyPool(object):
 
 pool = EntropyPool()
 
+try:
+    system_random = random.SystemRandom()
+except:
+    system_random = None
 
 def random_16():
-    return pool.random_16()
-
+    if system_random is not None:
+        return system_random.randrange(0, 65536)
+    else:
+        return pool.random_16()
 
 def between(first, last):
-    return pool.random_between(first, last)
+    if system_random is not None:
+        return system_random.randrange(first, last + 1)
+    else:
+        return pool.random_between(first, last)