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 newGenerator instance backed by PCG64.
| Name | Type | Default | Description |
|---|---|---|---|
seedValue | number | undefined | Optional seed value. If omitted, a random seed is used. |
Generator — A new random number generator.
Generator Class
TheGenerator 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).
| Name | Type | Default | Description |
|---|---|---|---|
size | number | number[] | undefined | Output shape. If omitted, returns a single float. |
NDArray | number — Uniform random values in [0, 1).
Generator.integers
Return random integers fromlow (inclusive) to high (exclusive).
| Name | Type | Default | Description |
|---|---|---|---|
low | number | — | Lowest integer (inclusive). If high is omitted, range is [0, low). |
high | number | undefined | Upper bound (exclusive). |
size | number | number[] | undefined | Output shape. |
NDArray | number — Random integers.
Generator.uniform
Draw samples from a uniform distribution over[low, high).
| Name | Type | Default | Description |
|---|---|---|---|
low | number | 0 | Lower boundary (inclusive). |
high | number | 1 | Upper boundary (exclusive). |
size | number | number[] | undefined | Output shape. |
NDArray | number — Uniform samples.
Generator.normal
Draw samples from a normal (Gaussian) distribution.| Name | Type | Default | Description |
|---|---|---|---|
loc | number | 0 | Mean of the distribution. |
scale | number | 1 | Standard deviation. |
size | number | number[] | undefined | Output shape. |
NDArray | number — Normal samples.
Generator.standard_normal
Draw samples from the standard normal distribution (mean=0, std=1).| Name | Type | Default | Description |
|---|---|---|---|
size | number | number[] | undefined | Output shape. |
NDArray | number — Standard normal samples.
Generator.exponential
Draw samples from an exponential distribution.| Name | Type | Default | Description |
|---|---|---|---|
scale | number | 1 | Scale parameter (beta = 1/lambda). |
size | number | number[] | undefined | Output shape. |
NDArray | number — Exponential samples.
Generator.poisson
Draw samples from a Poisson distribution.| Name | Type | Default | Description |
|---|---|---|---|
lam | number | 1 | Expected number of events (lambda). |
size | number | number[] | undefined | Output shape. |
NDArray | number — Poisson samples.
Generator.binomial
Draw samples from a binomial distribution.| Name | Type | Default | Description |
|---|---|---|---|
n | number | — | Number of trials. |
p | number | — | Probability of success. |
size | number | number[] | undefined | Output shape. |
NDArray | number — Binomial samples.
Generator.choice
Randomly select elements from an array or range.| Name | Type | Default | Description |
|---|---|---|---|
a | number | ArrayLike | — | If an integer, samples from arange(a). If an array, samples from its elements. |
size | number | number[] | undefined | Output shape. If omitted, returns a single value. |
replace | boolean | true | Whether to sample with replacement. |
p | ArrayLike | undefined | Probabilities for each element. Must sum to 1. |
NDArray | number — Random sample(s).
Generator.permutation
Return a randomly permuted copy of an array, or a permuted range.| Name | Type | Default | Description |
|---|---|---|---|
x | number | ArrayLike | — | If an integer, permute arange(x). If an array, return a shuffled copy. |
NDArray — Permuted array.
Generator.shuffle
Shuffle an array in-place along the first axis.| Name | Type | Default | Description |
|---|---|---|---|
x | NDArray | — | Array to be shuffled. Modified in-place. |
void