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.

Author vstinner
Recipients mark.dickinson, pitrou, rhettinger, tim.peters, vstinner
Date 2020-04-21.12:22:18
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1587471738.84.0.74477210463.issue40346@roundup.psfhosted.org>
In-reply-to
Content
Example with Python 3.8:
---
import random

class MyRandom(random.Random):
    def getrandbits(self, n):
        return 0

my = MyRandom()
print([my.randint(1, 6) for _ in range(3)])
print([my.random() for _ in range(3)])
---

Output:
---
[1, 1, 1]
[0.5654641798814677, 0.610057019404943, 0.7526620665660224]
---

[1, 1, 1] is what I expect, but what are these random [0.5654641798814677, 0.610057019404943, 0.7526620665660224] numbers?

This behavior is surprising me. I would expect the base class to be "empty", not to inherit Mersenne Twister. If I don't implement all required abstract methods: I would either expect an error when the class is created, or at least when the method is called.


Raymond:
> Am not sure I'm comfortable with you defining random() in pure python dividing by BPF -- that seems like a C level decision.

My PR 19631 doesn't change random.Random.random() (still implemented in C) nor random.SystemRandom.random() (same Python implementation): they should produce exactly the same random floating point numbers.
History
Date User Action Args
2020-04-21 12:22:18vstinnersetrecipients: + vstinner, tim.peters, rhettinger, mark.dickinson, pitrou
2020-04-21 12:22:18vstinnersetmessageid: <1587471738.84.0.74477210463.issue40346@roundup.psfhosted.org>
2020-04-21 12:22:18vstinnerlinkissue40346 messages
2020-04-21 12:22:18vstinnercreate