[issue40346] Redesign random.Random class inheritance

STINNER Victor report at bugs.python.org
Tue Apr 21 11:40:31 EDT 2020


STINNER Victor <vstinner at python.org> added the comment:

> It may be time to start emitting a warning if a Random subclass overrides random() but not getrandbits() or vice versa.

Does someone know if there are users outside the stdlib of random subclass which only implements random()? I guess that a deprecation warning should help us to know :-)

There is also an implementation detail: technically, it's also sems to possible to only implement _randbelow(): see __init_subclass__(). But I'm not sure what happens in Python 3.8 if you implement _randbelow() but not random() not getrandbits().

In my experience, all RNG either generates random bits or random bytes, but not directly random floats. Usually, floats are computed from the other operations: that's what I'm proposing in BaseRandom. random() is now computed from getrandbits(). But it remains possible to override random(), as done in random.Random.

----------

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


More information about the Python-bugs-list mailing list