Message366923
| Author |
vstinner |
| Recipients |
mark.dickinson, pitrou, rhettinger, serhiy.storchaka, tim.peters, vstinner |
| Date |
2020年04月21日.15:40:31 |
| SpamBayes Score |
-1.0 |
| Marked as misclassified |
Yes |
| Message-id |
<1587483631.7.0.924983920129.issue40346@roundup.psfhosted.org> |
| In-reply-to |
| Content |
> 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. |
|