NumPy | uniform method
Start your free 7-days trial now!
NumPy's random.uniform(~) method samples random values from a uniform distribution. In other words, the method returns an array of random floats.
To generate random floats from 0 to 1, use random(~) instead for convenience.
Parameters
1. lowlink | float or array-like of floats | optional
The lower bound (inclusive). By default, low=0.
2. highlink | float or array-like of floats
The upper bound (inclusive). By default, high=1.0.
3. sizelink | int or tuple of ints | optional
By default, a single value is returned if low and high are both float.
Return Value
If size is not specified and low and high are both scalars, then a single float is returned. Otherwise, a NumPy array of floats are returned.
Examples
Generating a single random float
To generate a single random float between 1 (inclusive) and 10 (inclusive):
np.random.uniform(low=1, high=10)
8.841304420902002
Generating multiple random floats
To generate multiple random floats between 1 (inclusive) and 10 (inclusive):
np.random.uniform(low=1, high=10, size=2)
array([4.2625794 , 8.20604428])