Python3 uniform() Function
Description
uniform() The method randomly generates the next real number in the [x,y] range.
Syntax
The syntax of the uniform() method is as follows:
import random
random.uniform(x, y)
**Note:** uniform() cannot be accessed directly; you need to import the random module and call the method through the static random object.
Parameters
- x -- the minimum value of the random number, inclusive.
- y -- the maximum value of the random number, inclusive.
Return Value
Returns a float N in the range if x
Example
The following shows examples of using the uniform() method:
Example
#!/usr/bin/python3
import
random
(
"
Random float from uniform(5, 10):
"
,
random
.
uniform
(
5
,
10
)
)
(
"
Random float from uniform(7, 14):
"
,
random
.
uniform
(
7
,
14
)
)
Running the example above produces:
uniform(5, 10) 的随机浮点数 : 7.054602800254241
uniform(7, 14) 的随机浮点数 : 12.552229882744296
Python3 Numbers