How to use Python's random number generator with a local seed? How to use Python's random number generator with a local seed? python-3.x python-3.x

How to use Python's random number generator with a local seed?


From the docs:

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 of Random 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)