random.expovariate

Full name
random.expovariate
Library
random
Syntax

random.expovariate(lambd)

Description

The random.expovariate function returns a random number drawn from an exponential distribution.

Parameters
  • lambd: Lambda parameter of the exponential distribution.
Result

The random.expovariate function returns a real number in the range [0, + infinity) if the lambd parameter is positive, or a real number in the range (-infinite, 0] if the lambd parameter is negative.

Examples

We can generate a random number extracted from an exponential distribution with a lambda parameter equal to 0.5 with the following code:

random.expovariate(0.5)
1.6287123635584828

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

import matplotlib.pyplot as plt
plt.figure(figsize = (8, 4))
plt.hist([random.expovariate(0.5) for i in range(100000)], bins = 100)
plt.show()
random.expovariate
Submitted by admin on Sun, 03/14/2021 - 11:02