bundles / numpy 2.5.0.dev0+git20251130.2de293a / 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() + aParameters
size: int or tuple of ints, optionalOutput shape. If the given shape is, e.g.,
(m, n, k), thenm * n * ksamples are drawn. Default is None, in which case a single value is returned.dtype: dtype, optionalDesired dtype of the result, only float64 and float32 are supported. Byteorder must be native. The default value is np.float64.
out: ndarray, optionalAlternative 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 floatsArray 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,))
✗5 * rng.random((3, 2)) - 5
✗See also
- uniform
Draw samples from the parameterized uniform distribution.
Aliases
-
numpy.random.Generator.random