Python3 random() Function

Python3 数字Python3 Numbers


Description

random()The method returns a randomly generated real number, which is 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 then call the method through the random static object.


Parameters

  • None

Return Value

Returns a randomly generated real number, which is in thehalf-open interval [0,1)range.


Examples

The following shows an example of using the random() method:

Examples

#!/usr/bin/python3
import random

# The first random number
print ("random() : ", random.random())

# The second random number
print ("random() : ", random.random())

The output of the above example after running is:

random() :  0.09690599908884856
random() :  0.8732120512570916

Python3 数字Python3 Numbers

Other Extensions