summaryrefslogtreecommitdiff
path: root/Lib/random.py
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2016-08-31 15:01:08 -0700
committerRaymond Hettinger <python@rcn.com>2016-08-31 15:01:08 -0700
commitc7bab7cbf5d6a8b442f2ed3e23543cb4ee826c87 (patch)
tree5cb8f216dfd9a2ff8e034a618971f87f0ce287b2 /Lib/random.py
parent4786787c07ba660c62a233ebfd16a8fcebc1c13e (diff)
downloadcpython-git-c7bab7cbf5d6a8b442f2ed3e23543cb4ee826c87.tar.gz
Issue #27706: Fix regression in random.seed(somestr, version=1)
Diffstat (limited to 'Lib/random.py')
-rw-r--r--Lib/random.py7
1 files changed, 7 insertions, 0 deletions
diff --git a/Lib/random.py b/Lib/random.py
index 5950735e3e..06513c824f 100644
--- a/Lib/random.py
+++ b/Lib/random.py
@@ -112,6 +112,13 @@ class Random(_random.Random):
import time
a = int(time.time() * 256) # use fractional seconds
+ if version == 1 and isinstance(a, (str, bytes)):
+ x = ord(a[0]) << 7 if a else 0
+ for c in a:
+ x = ((1000003 * x) ^ ord(c)) & 0xFFFFFFFFFFFFFFFF
+ x ^= len(a)
+ a = -2 if x == -1 else x
+
if version == 2:
if isinstance(a, (str, bytes, bytearray)):
if isinstance(a, str):