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 – 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.
Example 1
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)
Run Output
0.903656293362958
Example 2
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)
Run 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.
Related Tutorials
- Python Program to Flip a Coin
- Python Program to Generate Random Float
- Python – Generate Random String of Specific Length
- Python Program to Generate Random Password
- Python Program to Generate a Random Number of Specific Length
- Python Numpy – Create Array with Random Values
- PyTorch Create Tensor with Random Values and Specific Shape
- Python – Generate a Random Number – Positive or Negative
- Python Random Module Examples