Message366918
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. |
|
Date |
User |
Action |
Args |
2020-04-21 12:22:18 | vstinner | set | recipients:
+ vstinner, tim.peters, rhettinger, mark.dickinson, pitrou |
2020-04-21 12:22:18 | vstinner | set | messageid: <1587471738.84.0.74477210463.issue40346@roundup.psfhosted.org> |
2020-04-21 12:22:18 | vstinner | link | issue40346 messages |
2020-04-21 12:22:18 | vstinner | create | |
|