Python3 random() Function
Description
random() The method returns a randomly generated real number in thehalf-open interval [0,1) range.
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 call the method through the static random object.
Parameters
- None
Return Value
Returns a randomly generated real number in thehalf-open interval [0,1) range.
Example
The following shows examples of using the random() method:
Example
#!/usr/bin/python3
import
random
The first random number
(
"random() : "
,
random
.
random
(
)
)
The second random number
(
"random() : "
,
random
.
random
(
)
)
Running the example above produces:
random() : 0.09690599908884856
random() : 0.8732120512570916
Python3 Numbers