1
from core import asarray
2
from core import ndarray
9
def random_sample(size=None):
10
"""random_sample(size=None)
12
Return random floats in the half-open interval [0.0, 1.0).
14
Results are from the "continuous uniform" distribution over the
15
stated interval. To sample :math:`Unif[a, b), b > a` multiply
16
the output of `random_sample` by `(b-a)` and add `a`::
18
(b - a) * random_sample() + a
22
size : int or tuple of ints, optional
23
Defines the shape of the returned array of random floats. If None
24
(the default), returns a single float.
28
out : float or ndarray of floats
29
Array of random floats of shape `size` (unless ``size=None``, in which
30
case a single float is returned).
34
>>> np.random.random_sample()
36
>>> type(np.random.random_sample())
38
>>> np.random.random_sample((5,))
39
array([ 0.30220482, 0.86820401, 0.1654503 , 0.11659149, 0.54323428])
41
Three-by-two array of random numbers from [-5, 0):
43
>>> 5 * np.random.random_sample((3, 2)) - 5
44
array([[-3.99149989, -0.52338984],
45
[-2.99091858, -0.79479508],
46
[-1.23204345, -1.75224494]])
49
# this was my first implementation
50
# but each process does a lot of unnecessary work
51
#a = np.random.random_sample(size)
58
a = np.random.random_sample(size)
59
a = MPI.COMM_WORLD.bcast(a, 0)
61
a = ndarray(size, dtype=float)
64
buf[:] = np.random.random_sample(buf.shape)
73
This method is called when `RandomState` is initialized. It can be
74
called again to re-seed the generator. For details, see `RandomState`.
78
seed : int or array_like, optional
79
Seed for `RandomState`.
89
elif isinstance(seed,int):
90
np.random.seed(seed+me())