[issue44018] Bug in random.seed

2021-05-03 Thread Shreyan Avigyan
Shreyan Avigyan added the comment: One solution to these would be making a copy of the parameter using copy.deepcopy and then performing operations on that copy. (The downside of this solution is that it will change the behavior.) -- nosy: +shreyanavigyan ___

[issue44018] Bug in random.seed

2021-05-03 Thread Miguel Brito
Miguel Brito added the comment: The problem is that random seed will do ``` if isinstance(a, str): a = a.encode() a += _sha512(a).digest() a = int.from_bytes(a, 'big') ``` and that will modify the bytearray in place. >>> a = bytearray("1234

[issue44018] Bug in random.seed

2021-05-03 Thread Eugene Rossokha
Eugene Rossokha added the comment: I find the following behaviour very confusing: >>> import random >>> a = bytearray("1234", "utf-8") >>> b = bytearray("1234", "utf-8") >>> a == b True >>> random.seed(a) >>> a == b False >>> a bytearray(b'1234\xd4\x04U\x9f`.\xabo\xd6\x02\xacv\x80\xda\xcb\xfa\

[issue44018] Bug in random.seed

2021-05-03 Thread Raymond Hettinger
Raymond Hettinger added the comment: I don't see a bug here. As documented, "a str, bytes, or bytearray object gets converted to an int and all of its bits are used." The various input types are converted to an integer and it doesn't really matter how it is done as long as it is consistent

[issue44018] Bug in random.seed

2021-05-03 Thread Karthikeyan Singaravelan
Change by Karthikeyan Singaravelan : -- nosy: +mark.dickinson, rhettinger ___ Python tracker ___ ___ Python-bugs-list mailing list U

[issue44018] Bug in random.seed

2021-05-03 Thread Eugene Rossokha
New submission from Eugene Rossokha : https://github.com/python/cpython/blob/master/Lib/random.py#L157 If bytearray is passed as a seed, the function will change it. It either has to be documented, or the implementation should change. -- components: Library (Lib) messages: 392782 nosy: