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

bundles / numpy latest / 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() + 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.

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

np.random.random_sample()
type(np.random.random_sample())
np.random.random_sample((5,))
Three-by-two array of random numbers from [-5, 0):
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