Skip to main content
The Generator class is the recommended way to generate random numbers. It uses the PCG64 bit generator with SeedSequence initialization, exactly matching NumPy’s numpy.random.default_rng().

default_rng

Create a new Generator instance backed by PCG64.
Returns: Generator — A new random number generator.

Generator Class

The Generator class provides the following methods. Each method mirrors the corresponding legacy np.random.* function but uses the PCG64 bit generator.

Generator.random

Generate random floats in [0.0, 1.0).
Returns: NDArray | number — Uniform random values in [0, 1).

Generator.integers

Return random integers from low (inclusive) to high (exclusive).
Returns: NDArray | number — Random integers.

Generator.uniform

Draw samples from a uniform distribution over [low, high).
Returns: NDArray | number — Uniform samples.

Generator.normal

Draw samples from a normal (Gaussian) distribution.
Returns: NDArray | number — Normal samples.

Generator.standard_normal

Draw samples from the standard normal distribution (mean=0, std=1).
Returns: NDArray | number — Standard normal samples.

Generator.exponential

Draw samples from an exponential distribution.
Returns: NDArray | number — Exponential samples.

Generator.poisson

Draw samples from a Poisson distribution.
Returns: NDArray | number — Poisson samples.

Generator.binomial

Draw samples from a binomial distribution.
Returns: NDArray | number — Binomial samples.

Generator.choice

Randomly select elements from an array or range.
Returns: NDArray | number — Random sample(s).

Generator.permutation

Return a randomly permuted copy of an array, or a permuted range.
Returns: NDArray — Permuted array.

Generator.shuffle

Shuffle an array in-place along the first axis.
Returns: void

Full Example