How To Use Python's Random Number Generator With A Local Seed?
Python's random seems are global, so modules changing it will effect each other. While there are of course many 3rd party modules, is there a way using Python's standard library to
Solution 1:
The functions supplied by this module are actually bound methods of a hidden instance of the
random.Random
class. You can instantiate your own instances ofRandom
to get generators that don’t share state.
Make your own random.Random
instance and use that.
rng = random.Random(42)
number = rng.randint(10, 20)
Post a Comment for "How To Use Python's Random Number Generator With A Local Seed?"