Generate exponential random values in a given range

1.6k Views Asked by At

Need to generate random values ​​that follow an exponential distribution on an interval [a, b​​]. I tried using explained here Trucated distribution, but did not succeed

1

There are 1 best solutions below

0
On BEST ANSWER

This case has a simple solution because the cumulative distribution function for a truncated exponential variable and its inverse are easy to compute:

$$ F(x) = \frac{1}{e^{-\lambda a}-e^{-\lambda b}}\left[e^{-\lambda a}-e^{-\lambda x}\right] $$

so for a random variable, $u$ uniformly distributed over $[0,1]$, $ x=F^{-1}(u) $ follows the desired distribution. So (1) generate $u$ and (2), let

$$ x=-\frac{1}{\lambda} \log\left(e^{-\lambda a}-u\left[e^{-\lambda a} - e^{-\lambda b}\right]\right)$$ and you have it.