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 rhettinger
Recipients flybd5, remi.lapeyre, rhettinger
Date 2020-07-11.00:12:59
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1594426379.33.0.344189275698.issue41274@roundup.psfhosted.org>
In-reply-to
Content
> 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
History
Date User Action Args
2020-07-11 00:12:59rhettingersetrecipients: + rhettinger, remi.lapeyre, flybd5
2020-07-11 00:12:59rhettingersetmessageid: <1594426379.33.0.344189275698.issue41274@roundup.psfhosted.org>
2020-07-11 00:12:59rhettingerlinkissue41274 messages
2020-07-11 00:12:59rhettingercreate