random.uniform

Full name
random.uniform
Library
random
Syntax

random.uniform(a, b)

Description

The random.uniform function returns a random number in the range [a, b] drawn from a uniform distribution.

Parameters
  • a: Lower limit of the range from which to extract the random number.
  • b: Upper limit of the range from which to extract the random number.
Result

The random.uniform function returns a real number.

Examples

We can generate a random number in the range [10.0, 15.0] extracted from a uniform distribution with the following code:

random.uniform(10, 15)
11.410800732549799

To confirm the distribution from which the random numbers are extracted we can generate 10 thousand random numbers in the range [10.0, 15.0] and show its histogram:

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