Python3 uniform() function
Description
uniform()The method will randomly generate the next real number, which is in the[x,y]range.
Syntax
The following is the syntax of the uniform() method:
import random random.uniform(x, y)
Note:uniform() cannot be accessed directly. You need to import the random module, and then call the method through the random static object.
Parameters
- x -- The minimum value of the random number, inclusive.
- y -- The maximum value of the random number, inclusive.
Return Value
Returns a floating-point number N, with the value range being ifx<yThenx <= N <= y, ify<xTheny <= N <= x。
Example
The following shows an example of using the uniform() method:
Example
#!/usr/bin/python3
import random
print ("Random floating-point number of uniform(5, 10):", random.uniform(5, 10))
print ("Random floating-point number of uniform(7, 14):", random.uniform(7, 14))
The output result after running the above example is:
uniform(5, 10) 的随机浮点数 : 7.054602800254241 uniform(7, 14) 的随机浮点数 : 12.552229882744296Other Extensions
Python3 Numbers