Python random() function
Description
random() The method returns a randomly generated real number in the range [0,1).
Syntax
The syntax of the random() method is as follows:
import random
random.random()
**Note:** random() cannot be accessed directly; you need to import the random module and then call the method through the random static object.
Parameters
- None
Return Value
Returns a randomly generated real number in the range [0,1).
Example
The following shows examples of using the random() method:
Example
#!/usr/bin/python
-- coding: UTF-8 --
import
random
Generate the first random number
"
random() :
"
,
random
.
random
(
)
Generate the second random number
"
random() :
"
,
random
.
random
(
)
Running the example above produces:
random() : 0.281954791393
random() : 0.309090465205
Python Numbers