[issue40325] Random.seed does not affect string hash randomization leading to non-intuitive results

Yuval S report at bugs.python.org
Sat Apr 18 17:25:19 EDT 2020


New submission from Yuval S <sadan.yuval at gmail.com>:

The following code gives different results on each run, even though "``random.seed()``" is used:

>>> import random
>>> random.seed(6)
>>> x = set(str(i) for i in range(500))
>>> print(random.sample(x, 1))

presumably because of string hash randomization (see also #27706),
unless "``PYTHONHASHSEED``" is set. 

However, this is non-intuitive, especially as this random aspect of Python is not mentioned in `Notes on Reproducability <https://docs.python.org/3/library/random.html#notes-on-reproducibility>`_.

I would suggest this is either fixed (using the provided seed for string hash randomization as well) or documented.

----------
assignee: docs at python
components: Documentation, Library (Lib)
files: test.py
messages: 366741
nosy: Yuval S, docs at python
priority: normal
severity: normal
status: open
title: Random.seed does not affect string hash randomization leading to non-intuitive results
versions: Python 3.7, Python 3.8
Added file: https://bugs.python.org/file49075/test.py

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


More information about the Python-bugs-list mailing list