Python - Random Number using Exponential Distribution
Python - Generate Random Float using Exponential distribution
To generate a random floating point number using Exponential distribution in Python, use expovariate() function of Python random package.
In this tutorial, we shall learn how to generate a random floating point number based on Exponential distribution with specified mean and standard deviation.
Syntax of random.expovariate()
Following is the syntax of expovariate() function in random module.
f = random.expovariate(lambd)
where
Parameter | Description |
---|---|
lambd | Lambda (inverse of desired mean) for the Exponential distribution. |
expovariate() function returns a random floating point value based on the given lambda for the Exponential distribution.
Examples
1. Generate a float value
In this example, we shall use random.expovariate() function to generate a random floating point number based on the Exponential distribution with a lambda of 2.
Python Program
import random
lambd = 2
randomnumber = random.expovariate(lambd)
print(randomnumber)
Output
0.903656293362958
2. Generate a float value using a lambda of 100
In this example, we shall use random.expovariate() function to generate a random floating point number based on the Exponential distribution with a lambda of 100.
Python Program
import random
lambd = 100
randomnumber = random.expovariate(lambd)
print(randomnumber)
Output
0.0036099278098569603
Summary
In this tutorial of Python Examples, we learned how to generate a random floating point number using Exponential distribution, with the help of well detailed example programs.