Python random uniform() Method
The Python random uniform() method will randomly generate the next real number in the range [x,y].
Python random uniform() Syntax
Here is the syntax of the uniform() method:
import random
random.uniform(x, y)
Note: uniform() is not directly accessible, you need to import the random module and then call the method via the random static object.
Python random uniform() Parameters
- x : the minimum value of the random number containing the value.
- y : the maximum value of the random number containing the value.
Python random uniform() Return Value
Returns a floating point number N in the range x <= N <= y if x < y and y <= N <= x if y < x.
Python random uniform() Example
The following shows an example of using the uniform() method.
#!/usr/bin/python3
import random
print ("uniform(50, 100) random floating point numbers : ", random.uniform(50, 100))
print ("uniform(70, 140) random floating point numbers : ", random.uniform(70, 140))
Output: