Q:

Generate random array of floats between a range

I haven't been able to find a function to generate an array of random floats of a given length between a certain range.
I've looked at Random sampling but no function seems to do what I need.
random.uniform comes close but it only returns a single element, not a specific number.
This is what I'm after:
ran_floats = some_function(low=0.5, high=13.3, size=50)

which would return an array of 50 random non-unique floats (ie: repetitions are allowed) uniformly distributed in the range [0.5, 13.3].
Is there such a function?

A:

np.random.uniform fits your use case:
sampl = np.random.uniform(low=0.5, high=13.3, size=(50,))

Update Oct 2019:
While the syntax is still supported, it looks like the API changed with NumPy 1.17 to support greater control over the random number generator. Going forward the API has changed and you should look at https://docs.scipy.org/doc/numpy/reference/random/generated/numpy.random.Generator.uniform.html
The enhancement proposal is here: https://numpy.org/neps/nep-0019-rng-policy.html

A:

Why not use a list comprehension?
In Python 2
ran_floats = [random.uniform(low,high) for _ in xrange(size)]

In Python 3, range works like xrange(ref)
ran_floats = [random.uniform(low,high) for _ in range(size)]

A:

Why not to combine random.uniform with a list comprehension?
>>> def random_floats(low, high, size):
...    return [random.uniform(low, high) for _ in xrange(size)]
... 
>>> random_floats(0.5, 2.8, 5)
[2.366910411506704, 1.878800401620107, 1.0145196974227986, 2.332600336488709, 1.945869474662082]

