The Wayback Machine - https://web.archive.org/web/20240525001455/https://www.geeksforgeeks.org/random-expovariate-function-in-python/
Open In App

random.expovariate() function in Python

Last Updated : 23 Dec, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

random module is used to generate random numbers in Python. Not actually random, rather this is used to generate pseudo-random numbers. That implies that these randomly generated numbers can be determined.

random.expovariate()

expovariate() is an inbuilt method of the random module. It is used to return a random floating point number with exponential distribution.

Syntax : random.expovariate(lambda)

Parameters :
lambda : a non zero value

Returns : a random exponential distribution floating number
if the parameter is positive, the results range from 0 to positive infinity
if the parameter is negative, the results range from 0 to negative infinity

Example 1:




# import the random module
import random
  
# determining the values of the parameter
lambda = 1.5
  
# using the expovariate() method
print(random.expovariate(lambda))


Output :

0.22759592233982198

Example 2: We can generate the number multiple times and plot a graph to observe the exponential distribution.




# import the required libraries 
import random 
import matplotlib.pyplot as plt 
    
# store the random numbers in a  
# list 
nums = [] 
alpha = 3
    
for i in range(100): 
    temp = random.paretovariate(alpha)
    nums.append(temp) 
        
# plotting a graph 
plt.plot(nums) 
plt.show()


Output :

Example 3: We can create a histogram to observe the density of the exponential distribution.




# import the required libraries 
import random 
import matplotlib.pyplot as plt 
    
# store the random numbers in a list 
nums = [] 
lambda = 1.5
    
for i in range(10000): 
    temp = random.expovariate(lambda)
    nums.append(temp) 
        
# plotting a graph 
plt.hist(nums, bins = 200) 
plt.show()


Output :



Previous Article
Next Article

Similar Reads

Python Random - random() Function
There are certain situations that involve games or simulations which work on a non-deterministic approach. In these types of situations, random numbers are extensively used in the following applications: Creating pseudo-random numbers on Lottery scratch cardsreCAPTCHA on login forms uses a random number generator to define different numbers and ima
3 min read
Random sampling in numpy | random() function
numpy.random.random() is one of the function for doing random sampling in numpy. It returns an array of specified shape and fills it with random floats in the half-open interval [0.0, 1.0). Syntax : numpy.random.random(size=None) Parameters : size : [int or tuple of ints, optional] Output shape. If the given shape is, e.g., (m, n, k), then m * n *
2 min read
NumPy random.noncentral_f() | Get Random Samples from noncentral F distribution
The NumPy random.noncentral_f() method returns the random samples from the noncentral F distribution. Example C/C++ Code import numpy as np import matplotlib.pyplot as plt gfg = np.random.noncentral_f(1.24, 21, 3, 1000) count, bins, ignored = plt.hist(gfg, 50, density = True) plt.show() Output: Syntax Syntax: numpy.random.noncentral_f(dfnum, dfden,
1 min read
Python | random.sample() function
sample() is an inbuilt function of random module in Python that returns a particular length list of items chosen from the sequence i.e. list, tuple, string or set. Used for random sampling without replacement. Syntax : random.sample(sequence, k) Parameters: sequence: Can be a list, tuple, string, or set. k: An Integer value, it specify the length o
2 min read
random.vonmisesvariate() function in Python
random module is used to generate random numbers in Python. Not actually random, rather this is used to generate pseudo-random numbers. That implies that these randomly generated numbers can be determined. random.vonmisesvariate() vonmisesvariate() is an inbuilt method of the random module. It is used to return a random floating point number with v
2 min read
random.paretovariate() function in Python
random module is used to generate random numbers in Python. Not actually random, rather this is used to generate pseudo-random numbers. That implies that these randomly generated numbers can be determined. random.paretovariate() paretovariate() is an inbuilt method of the random module. It is used to return a random floating point number with Paret
2 min read
random.weibullvariate() function in Python
random module is used to generate random numbers in Python. Not actually random, rather this is used to generate pseudo-random numbers. That implies that these randomly generated numbers can be determined. random.weibullvariate() weibullvariate() is an inbuilt method of the random module. It is used to return a random floating point number with Wei
2 min read
random.normalvariate() function in Python
random module is used to generate random numbers in Python. Not actually random, rather this is used to generate pseudo-random numbers. That implies that these randomly generated numbers can be determined. random.normalvariate() normalvariate() is an inbuilt method of the random module. It is used to return a random floating point number with norma
2 min read
random.gauss() function in Python
random module is used to generate random numbers in Python. Not actually random, rather this is used to generate pseudo-random numbers. That implies that these randomly generated numbers can be determined. random.gauss() gauss() is an inbuilt method of the random module. It is used to return a random floating point number with gaussian distribution
2 min read
random.lognormvariate() function in Python
random module is used to generate random numbers in Python. Not actually random, rather this is used to generate pseudo-random numbers. That implies that these randomly generated numbers can be determined. random.lognormvariate() lognormvariate() is an inbuilt method of the random module. It is used to return a random floating point number with log
2 min read
Article Tags :
Practice Tags :