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: Internal Random class calling seed() with incorrect argument
Type: behavior Stage: resolved
Components: Extension Modules Versions: Python 3.10
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: rhettinger Nosy List: Amir, rhettinger
Priority: normal Keywords: easy (C), patch

Created on 2020-10-11 21:52 by rhettinger, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 22668 merged Amir, 2020-10-12 11:43
Messages (4)
msg378457 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2020-10-11 21:52
The C code in random_new() incorrectly calls random_seed() with an args tuple. Instead, it should use first element of the args tuple.

This matters because we've deprecated using PyObject_Hash() in random_seed().  Once that is removed, _random.Random(someseed) won't work at all (there's a test for it).

# Public API is correct
>>> from random import Random
>>> r = Random()
>>> r.seed(8675309)
>>> r.random()
0.40224696110279223
>>> r = Random(8675309)
>>> r.random()
0.40224696110279223

# Private API is incorrect for Random(someseed)
>>> from _random import Random
>>> r = Random()
>>> r.seed(8675309)
>>> r.random()
0.40224696110279223
>>> r = Random(8675309)              
>>> r.random()
0.21095576307886765                  <=== This is wrong
msg378482 - (view) Author: Amir Mohamadi (Amir) * Date: 2020-10-12 09:45
Can I open a PR for it?
msg383561 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2020-12-21 23:45
New changeset b8fde8b5418b75d2935d0ff93b20d45d5350f206 by AMIR in branch 'master':
bpo-42008: Fix internal _random.Random() seeding for the one argument case (GH-22668)
https://github.com/python/cpython/commit/b8fde8b5418b75d2935d0ff93b20d45d5350f206
msg383562 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2020-12-21 23:46
Thanks for the PR :-)
History
Date User Action Args
2022-04-11 14:59:36adminsetgithub: 86174
2020-12-21 23:46:42rhettingersetstatus: open -> closed
versions: - Python 3.8, Python 3.9
messages: + msg383562

assignee: rhettinger
resolution: fixed
stage: patch review -> resolved
2020-12-21 23:45:59rhettingersetmessages: + msg383561
2020-10-12 11:43:24Amirsetkeywords: + patch
stage: patch review
pull_requests: + pull_request21641
2020-10-12 09:45:47Amirsetnosy: + Amir
messages: + msg378482
2020-10-11 21:52:41rhettingercreate