From 132a7d7cdbc7cb89fa1c1f4e8192241c3d68f549 Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Sun, 17 Sep 2017 09:04:30 -0700 Subject: bpo-31482: Missing bytes support for random.seed() version 1 (#3614) bpo-31482: Missing bytes support for random.seed() version 1 #3614 --- Lib/random.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'Lib/random.py') diff --git a/Lib/random.py b/Lib/random.py index 01c0c3d25f..91065b7e30 100644 --- a/Lib/random.py +++ b/Lib/random.py @@ -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 -- cgit v1.2.1