Python uniform() function
Description
uniform() The method randomly generates the next real number in the range [x, y].
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/python
-- coding: UTF-8 --
import
random
"
The random number from uniform(5, 10) is:
"
,
random
.
uniform
(
5
,
10
)
"
The random number from uniform(7, 14) is:
"
,
random
.
uniform
(
7
,
14
)
Running the example above produces:
uniform(5, 10) 的随机数为 : 6.98774810047
uniform(7, 14) 的随机数为 : 12.2243345905
Python Numbers