bpo-31482: Missing bytes support for random.seed() version 1 (#3614)

bpo-31482: Missing bytes support for random.seed() version 1 #3614
This commit is contained in:
Raymond Hettinger 2017-09-17 09:04:30 -07:00 committed by GitHub
parent 63c591c0b0
commit 132a7d7cdb
3 changed files with 31 additions and 2 deletions

View file

@ -110,9 +110,10 @@ class Random(_random.Random):
"""
if version == 1 and isinstance(a, (str, bytes)):
a = a.decode('latin-1') if isinstance(a, bytes) else a
x = ord(a[0]) << 7 if a else 0
for c in a:
x = ((1000003 * x) ^ ord(c)) & 0xFFFFFFFFFFFFFFFF
for c in map(ord, a):
x = ((1000003 * x) ^ c) & 0xFFFFFFFFFFFFFFFF
x ^= len(a)
a = -2 if x == -1 else x