This is a pre-release version (latest). Go to latest (2.4.4)
{ } Raw JSON

bundles / numpy latest / numpy / random / _generator / Generator / random

cython_function_or_method

numpy.random._generator:Generator.random

Summary

Return random floats in the half-open interval [0.0, 1.0).

Extended Summary

Results are from the "continuous uniform" distribution over the stated interval. To sample use uniform or multiply the output of random by (b - a) and add a

(b - a) * random() + a

Parameters

size : int or tuple of ints, optional

Output shape. If the given shape is, e.g., (m, n, k), then m * n * k samples are drawn. Default is None, in which case a single value is returned.

dtype : dtype, optional

Desired dtype of the result, only float64 and float32 are supported. Byteorder must be native. The default value is np.float64.

out : ndarray, optional

Alternative output array in which to place the result. If size is not None, it must have the same shape as the provided size and must match the type of the output values.

Returns

out : float or ndarray of floats

Array of random floats of shape size (unless size=None, in which case a single float is returned).

Examples

rng = np.random.default_rng()
rng.random()
type(rng.random())
rng.random((5,))
Three-by-two array of random numbers from [-5, 0):
5 * rng.random((3, 2)) - 5

See also

uniform

Draw samples from the parameterized uniform distribution.

Aliases

  • numpy.random.Generator.random

Referenced by