[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:

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

Python tracker <report at bugs.python.org>

More information about the docs mailing list