random.random

Full name
random.random
Library
random
Syntax

random.random()

Description

The random.random function returns a random number in the range [0.0, 1.0) drawn from a uniform distribution.

Parameters

The random.random function takes no arguments.

Result

The random.random function returns a real number.

Examples

We can generate a random number in the range [0.0, 1.0) extracted from a uniform distribution with the following code:

random.random()
0.46216883512905227

To confirm the distribution from which the random numbers are extracted we can generate 10 thousand random numbers and show their histogram:

import matplotlib.pyplot as plt
plt.figure(figsize = (8, 4))
plt.hist([random.random() for i in range(10000)])
plt.show()
random.random
Submitted by admin on Sat, 03/13/2021 - 08:47