Easy Tutorial
❮ Python List Python Func Number Cos ❯

Python3 random() Function

Python3 Numbers


Description

The random() method returns a randomly generated real number within the half-open interval [0,1).


Syntax

Here is the syntax for the random() method:

import random

random.random()

Note: random() cannot be accessed directly. It requires importing the random module and then calling this method via the random static object.


Parameters


Return Value

Returns a randomly generated real number within the half-open interval [0,1).


Example

Below is an example demonstrating the use of the random() method:

#!/usr/bin/python3
import random

# First random number
print("random() : ", random.random())

# Second random number
print("random() : ", random.random())

The output of the above example is:

random() :  0.09690599908884856
random() :  0.8732120512570916

Python3 Numbers

❮ Python List Python Func Number Cos ❯