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 ofrandom — 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, likerand.
Returns:
NDArray | number — Samples from the standard normal distribution.
randint
Return random integers fromlow (inclusive) to high (exclusive).
Returns:
NDArray | number — Random integers in [low, high).
random_sample
Alias forrandom(). Return random floats in [0.0, 1.0).
Returns:
NDArray | number — Random values in [0, 1).
ranf
Alias forrandom(). Return random floats in [0.0, 1.0).
Returns:
NDArray | number — Random values in [0, 1).
sample
Alias forrandom(). Return random floats in [0.0, 1.0).
Returns:
NDArray | number — Random values in [0, 1).
random_integers
Return random integers betweenlow and high, inclusive on both ends.
Returns:
NDArray | number — Random integers in [low, high].
bytes
Return random bytes as aUint8Array.
Returns:
Uint8Array — Array of random bytes.
choice
Generate a random sample from a given 1-D array or fromrange(a) when a is an integer.