Skip to main content
All functions on this page are accessed via the np.random namespace and use the global MT19937 generator. Seed with np.random.seed() for reproducible results.
As of v1.2.0, random functions on this page (rand, randn, random, randint, uniform, normal, choice, shuffle, permutation, bytes) are now implemented as Zig-compiled WASM kernels. With np.random.seed(n), outputs match NumPy exactly for the same seed across every function listed here.

random

Generate random floats in the half-open interval [0.0, 1.0).
Returns: NDArray | number — Random values in [0, 1).

rand

Random values in a given shape. Variadic form of random — pass dimensions as separate arguments.
Returns: NDArray | number — Random values in [0, 1).

randn

Return samples from the standard normal distribution (mean=0, std=1). Variadic shape, like rand.
Returns: NDArray | number — Samples from the standard normal distribution.

randint

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

random_sample

Alias for random(). Return random floats in [0.0, 1.0).
Returns: NDArray | number — Random values in [0, 1).

ranf

Alias for random(). Return random floats in [0.0, 1.0).
Returns: NDArray | number — Random values in [0, 1).

sample

Alias for random(). Return random floats in [0.0, 1.0).
Returns: NDArray | number — Random values in [0, 1).

random_integers

Deprecated. Use randint instead.
Return random integers between low and high, inclusive on both ends.
Returns: NDArray | number — Random integers in [low, high].

bytes

Return random bytes as a Uint8Array.
Returns: Uint8Array — Array of random bytes.

choice

Generate a random sample from a given 1-D array or from range(a) when a is an integer.

permutation

Randomly permute a sequence or return a permuted range.

shuffle

Shuffle an array in place along the first axis.