[docs] [issue32554] random.seed(tuple) uses the randomized hash function and so is not reproductible
Raymond Hettinger
report at bugs.python.org
Sun Jun 24 15:44:55 EDT 2018
Raymond Hettinger <raymond.hettinger at gmail.com> added the comment:
I'm thinking of something like this:
$ git diff
diff --git a/Lib/random.py b/Lib/random.py
index 1e0dcc87ed..f479e66ada 100644
--- a/Lib/random.py
+++ b/Lib/random.py
@@ -136,12 +136,17 @@ class Random(_random.Random):
x ^= len(a)
a = -2 if x == -1 else x
- if version == 2 and isinstance(a, (str, bytes, bytearray)):
+ elif version == 2 and isinstance(a, (str, bytes, bytearray)):
if isinstance(a, str):
a = a.encode()
a += _sha512(a).digest()
a = int.from_bytes(a, 'big')
+ elif not isinstance(a, (type(None), int, float, str, bytes, bytearray)):
+ _warn('Seeding based on hashing is deprecated.\n'
+ 'The only supported seed types are None, int, float, '
+ 'str, bytes, and bytearray.', DeprecationWarning, 2)
+
super().seed(a)
self.gauss_next = None
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue32554>
_______________________________________
More information about the docs
mailing list