Raymond Hettinger <[email protected]> added the comment:
> 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
----------
nosy: +rhettinger
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue41274>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com