Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python3 random() Function

Python3 random() Function

Python3 Numbers Python3 Numbers


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


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

print

(

"random() : "

,

random

.

random

(

)

)

The second random number

print

(

"random() : "

,

random

.

random

(

)

)

Running the example above produces:


random() :  0.09690599908884856
random() :  0.8732120512570916

Python3 Numbers Python3 Numbers