nlcpy.random.RandomState.random_sample

RandomState.random_sample(self, size=None)

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

Results are from the “continuous uniform” distribution over the stated interval. To sample Unif[a, b), b > a multiply the output of random_sample by (b-a) and add a:

(b - a) * random_sample() + a
Parameters
sizeint 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
outndarray of floats

Array of random floats of shape size.

Examples

>>> import nlcpy as vp
>>> vp.random.random_sample()            
array(0.80430306) # random
>>> type(vp.random.random_sample())
<class 'nlcpy.core.core.ndarray'>
>>> vp.random.random_sample((5,))        
array([0.56570372, 0.13436335, 0.62341754, 0.88471288, 0.13366607])

Three-by-two array of random numbers from [-5, 0):

>>> 5 * vp.random.random_sample((3, 2)) - 5  
array([[-3.99149989, -0.52338984], # random
       [-2.99091858, -0.79479508],
       [-1.23204345, -1.75224494]])