bundles / numpy 2.4.3 / numpy / random / RandomState / random_sample
cython_function_or_method
numpy.random:RandomState.random_sample
Signature
def random_sample ( size = None ) 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 multiply the output of random_sample by (b-a) and add a:
(b - a) * random_sample() + 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.
Returns
out: float or ndarray of floatsArray of random floats of shape
size(unlesssize=None, in which case a single float is returned).
Examples
np.random.random_sample()
✗type(np.random.random_sample())
✓np.random.random_sample((5,))
✗5 * np.random.random_sample((3, 2)) - 5
✗See also
- random.Generator.random
which should be used for new code.
Aliases
-
numpy.random.random_sample -
numpy.random.RandomState.random_sample