[docs] [issue32554] random seed is not consistent when using tuples with a str element

STINNER Victor report at bugs.python.org
Mon Jan 15 04:13:25 EST 2018


STINNER Victor <victor.stinner at gmail.com> added the comment:

random.seed(str) uses:

        if 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')

Whereas for other types, random.seed(obj) uses hash(obj), and hash is randomized by default in Python 3.

Yeah, the random.seed() documentation should describe the implementation and explain that hash(obj) is used and that the hash function is randomized by default:
https://docs.python.org/dev/library/random.html#random.seed

----------
assignee:  -> docs at python
components: +Documentation
nosy: +docs at python, mark.dickinson, rhettinger, vstinner

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue32554>
_______________________________________


More information about the docs mailing list