Signature
np.random.default_rng(seed=None)What it does
default_rng returns a Generator with methods such as integers, normal, and permutation. Passing a seed recreates the same starting stream for repeatable experiments.
Parameters
seedint, array_like, or Noneoptional- Initial state for the generator. None uses fresh entropy.
Returns
Generator
Example
pythonnp.random.default_rng example
import numpy as np
rng = np.random.default_rng(7)
print(rng.integers(1, 7, size=5))Watch out for
- Re-seeding inside a loop can produce repeated blocks of values.
- A seed makes a run repeatable, not cryptographically secure.