[New-bugs-announce] [issue42008] Internal Random class calling seed() with incorrect argument

Raymond Hettinger report at bugs.python.org
Sun Oct 11 17:52:41 EDT 2020


New submission from Raymond Hettinger <raymond.hettinger at gmail.com>:

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

----------
components: Extension Modules
keywords: easy (C)
messages: 378457
nosy: rhettinger
priority: normal
severity: normal
status: open
title: Internal Random class calling seed() with incorrect argument
type: behavior
versions: Python 3.10, Python 3.8, Python 3.9

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


More information about the New-bugs-announce mailing list