import random
import math
from scipy.stats import expon
from matplotlib import pyplot as plt
#
# If the random variable X is exponentially distributed with parameter
# lambda, then its pdf is
# pdf_X(x)=lambda*exp(-lambda*x)
#
# Therefore the random variable Y defined by Y=pdf_X(X) is uniformly
# distributed like U(0,1) (by CDF inversion theorem). Therefore we have
#
# Y = U(0,1)= lambda*exp(-lambda*X)
#
# Now solve for X:
# U(0,1)/lambda = exp(-lambda*X)
#
# log(U(0,1)/lambda)=-lambda*X
#
# (-1/lambda)*log(U(0,1)/lambda) = X
#
# Therefore to generate 1000 points of exponentially distributed data
# with parameter, say, lambda=5, we may write
expdata=[(-1/5)*math.log(random.uniform(0,1)/5) for x in list(range(0,1000))]
#
# we will later plot the histogram of this data later with plt.hist(expdata)
#
#
# We want to fit and exponential random variable to this data list expdata.
#
rv_continuous.fit(expon,data)