Message373490
> is it possible to write a new module that overrides the seed()
> method in the random library in its initialization code and
> replaces it with this method of seeding the generator?
Yes. The simplest way is override seed() in a subclass. You can put that subclass in a new module if you like and can even call the class "Random" if desired.
>>> class InputRandom(random.Random):
def seed(self, a=None):
if a is None:
a = int(input('Enter a seed: '))
super().seed(a)
>>> r = InputRandom()
Enter a seed: 1234
>>> r.random()
0.9664535356921388
>>> r.random()
0.4407325991753527
>>> r.seed()
Enter a seed: 1234
>>> r.random()
0.9664535356921388
>>> r.seed(1234)
>>> r.random()
0.9664535356921388 |
|
Date |
User |
Action |
Args |
2020-07-11 00:12:59 | rhettinger | set | recipients:
+ rhettinger, remi.lapeyre, flybd5 |
2020-07-11 00:12:59 | rhettinger | set | messageid: <1594426379.33.0.344189275698.issue41274@roundup.psfhosted.org> |
2020-07-11 00:12:59 | rhettinger | link | issue41274 messages |
2020-07-11 00:12:59 | rhettinger | create | |
|