np.random.seed() sets a global seed for NumPy’s legacy random number generator. This global state can be unintentionally modified elsewhere in your code, leading to unpredictable results.
In contrast, np.random.default_rng() creates a new, independent instance of NumPy’s modern Generator (based on the PCG64 algorithm). Each instance maintains its own state and does not affect or rely on any global seed.
Key difference:
You can’t “reseed” the global RNG with default_rng(), it intentionally avoids global state for better reproducibility and isolation.
To get repeatable results, pass a seed when creating the generator:
rng = np.random.default_rng(42)
value = rng.random()
This is the recommended approach in modern NumPy (version 1.17 or later).
np.random.default_rng()is create a Generator object to which you can pass aseedargument at its creation for reproducibility. Once you Generator object is created, you can use it to call pre-defined distributions (gumbel, normal, pareto, poisson...), generate random data or do other operations (all described in the documentation). To sum it up, you first need to create a generator, before being able to use its predefined methods