summaryrefslogtreecommitdiffstats
path: root/Lib/random.py
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2010-12-08 01:13:53 (GMT)
committerRaymond Hettinger <python@rcn.com>2010-12-08 01:13:53 (GMT)
commit3fcf0029945d8c6f866fdbb98517136999d7be7e (patch)
tree189af74502f0ce1090dcb6abf5339d4174c9a640 /Lib/random.py
parent10e05e17a3e7657ecdc4c7986d35275d76c6d603 (diff)
downloadcpython-3fcf0029945d8c6f866fdbb98517136999d7be7e.zip
cpython-3fcf0029945d8c6f866fdbb98517136999d7be7e.tar.gz
cpython-3fcf0029945d8c6f866fdbb98517136999d7be7e.tar.bz2
Update whatsnew. Salt the random number seed.
Diffstat (limited to 'Lib/random.py')
-rw-r--r--Lib/random.py11
1 files changed, 7 insertions, 4 deletions
diff --git a/Lib/random.py b/Lib/random.py
index 83a070c..7f63388 100644
--- a/Lib/random.py
+++ b/Lib/random.py
@@ -43,6 +43,7 @@ from math import log as _log, exp as _exp, pi as _pi, e as _e, ceil as _ceil
from math import sqrt as _sqrt, acos as _acos, cos as _cos, sin as _sin
from os import urandom as _urandom
import collections as _collections
+from hashlib import sha512 as _sha512
__all__ = ["Random","seed","random","uniform","randint","choice","sample",
"randrange","shuffle","normalvariate","lognormvariate",
@@ -110,10 +111,12 @@ class Random(_random.Random):
import time
a = int(time.time() * 256) # use fractional seconds
- if version == 2 and isinstance(a, (str, bytes, bytearray)):
- if isinstance(a, str):
- a = a.encode("utf8")
- a = int.from_bytes(a, 'big')
+ if version == 2:
+ if isinstance(a, (str, bytes, bytearray)):
+ if isinstance(a, str):
+ a = a.encode("utf8")
+ a += _sha512(a).digest()
+ a = int.from_bytes(a, 'big')
super().seed(a)
self.gauss_next = None