mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
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:
parent
63c591c0b0
commit
132a7d7cdb
3 changed files with 31 additions and 2 deletions
|
@ -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
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue