Hi Robert,
Thanks for the information and the offer. My use case is development of algorithms where I want to be able to test variations of the algorithm while keeping the same (simulated or generated) data. Related to that are example scripts part of the documentation that I want to always have the same result.
Creating a generator and passing that (someway or the other) is a good approach, but it requires some refactoring of the code. Especially for third-party code I would like to avoid this (to be honest, most external code is still using the old numpy random number interface, so there we can use the old style of setting the seed)
Ah, okay, so you're replacing the old global with a new global Generator instance in your own code as an easier transitional step.
# global instance
rng = np.random.default_rng()
def seed_global_rng(seed=None):
# Create the same type of BitGenerator with the given seed, and then copy its state over to the global.
bg_cls = type(rng.bit_generator)
bg = bg_cls(seed)
rng.bit_generator.state = bg.state
I do recommend moving to passing around a Generator when you can; even in the older system, we've always recommended passing around a RandomState instance.
--