This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: _Random.seed() is called twice
Type: Stage: resolved
Components: Extension Modules Versions: Python 3.11
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: mark.dickinson, rhettinger, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2021-05-28 14:27 by serhiy.storchaka, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 26455 merged serhiy.storchaka, 2021-05-30 10:36
Messages (3)
msg394663 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2021-05-28 14:27
_Random.seed() is called twice: first it is called in _Random.__new__(), then it is called in Random.__init__(). By default it reads system enthropy, so it consumes global system resource without need.
msg394754 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2021-05-30 06:41
Consider moving seeding from _random.Random.__new__ to _random.Random.__init__.  Since random.Random.__init__ doesn't call the super(), the C version never gets called, avoiding the double seeding.   But, it still lets _random.Random function as a standalone class.
msg394823 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2021-05-31 20:24
New changeset a6a20658814e8668966fc86de0e80a4772864781 by Serhiy Storchaka in branch 'main':
bpo-44260: Do not read system entropy without need in Random() (GH-26455)
https://github.com/python/cpython/commit/a6a20658814e8668966fc86de0e80a4772864781
History
Date User Action Args
2022-04-11 14:59:46adminsetgithub: 88426
2021-05-31 20:24:57serhiy.storchakasetstatus: open -> closed
stage: patch review -> resolved
resolution: fixed
versions: + Python 3.11
2021-05-31 20:24:28serhiy.storchakasetmessages: + msg394823
2021-05-30 10:36:22serhiy.storchakasetkeywords: + patch
stage: patch review
pull_requests: + pull_request25051
2021-05-30 06:41:51rhettingersetmessages: + msg394754
2021-05-28 14:27:28serhiy.storchakacreate