[issue32554] random.seed(tuple) uses the randomized hash function and so is not reproductible
Raymond Hettinger <raymond.hettinger@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@bugs.python.org> <https://bugs.python.org/issue32554> _______________________________________
participants (1)
-
Raymond Hettinger