[issue32554] random.seed(tuple) uses the randomized hash function and so is not reproductible
Lee Griffiths <poddster@gmail.com> added the comment: a) This below issue added doc to py2.7 that calls out PYTHONHASHSEED, but py doesn't currently contain those words https://bugs.python.org/issue27706 It'd be useful to have the something whether the "behaviour" is fixed or not, as providing other objects (like a tuple) will still be non-deterministic. b) I don't know if this is the correct issue to heap this on, but I think it might as you're looking at changing the seed function? The documentation for `object.__hash__` calls out `str`, `bytes` and `datetime` as being affected by `PYTHONHASHSEED`. Doesn't it seem odd that there's a workaround in the seed function for str and bytes, but not for datetime? https://docs.python.org/3/reference/datamodel.html#object.__hash__ I mainly point this out as seeding random with the current date/time is idiomatic in many languages and environments (usually used when you log the seed to be able to recreate things later, or just blindly copying the historical use `srand(time(NULL))` from C programs!). Anyone shoving a datetime straight into seed() is going to find it non-deterministic and might not understand why, or even notice, especially as the documentation for seed() doesn't call this out. Those "in the know" will get a unix timestamp out of the datetime and put that in seed instead, but I feel that falls under the same argument as users-in-the-know SHA512ing a string, mentioned above, which is undesirable and apparently something the function should implement and not users. Would it be wise for datetime to have a specific implementation as well? ---------- nosy: +poddster _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue32554> _______________________________________
participants (1)
-
Lee Griffiths