Generate random number between 0 and 1 with (negative)exponential distribution

java, probability, random

Solution

The negative exponential distribution has support on the range [0, ∞), so I'm interpreting your question as a request for a truncated negative exponential. The Cumulative Distribution Function for such a beast with lower limit `l >= 0`, upper limit `h > l`, and rate `λ` is

F(x) = (exp(-λl) - exp(-λx)) / (exp(-λl) - exp(-λh))

We can find the inversion by setting this equal to `U`, a uniform(0,1) random number, and solving for `x`:

X = -ln(exp(-λl) - (exp(-λl) - exp(-λh)) * U) / λ

Since you specified lower and upper limits of 0 and 1, respectively, this reduces to

X = -ln(1 - (1 - exp(-λ)) * U) / λ

Replace `U` with a call to your favorite U(0,1) generator and that's your algorithm for generating `X`'s with the desired distribution.

Here's a histogram of 10,000 values generated with `λ = 5`. Smaller values of `λ` give a flatter distribution, larger values show a more rapid exponential drop off.

Problem

Heyho, I'm trying to generate a random number between 0.0 and 1.0 with exponential/negative exponential distribution. There is an article, which tells that you have to get the "quantile function". But the results are still greater than 1.0. So I would need to scale my equation somehow. My goal is to generate a random number in a range, where for example higher/lower values have a higher probability. (The distribution should be scalable) Related questions(don't truncate the result to [0,1]): - Pseudorandom Number Generator - Exponential Distribution - Generate random number between 0 and 1 with guassian distributes

Original source

Related problems