General principle
We can generate random numbers via an inverse problem.
First, it turns out that is not difficult for a modern computers to generate random numbers uniformly, and, between 0 and 1 .
Now, suppose we want to generate random numbers from another random variable X, with cummulative distribution function FX.
Recall that the values of FX lie between 0 and 1.
Also, not only is FX a non-decreasing function, for most common cases it’s actually strictly increasing, which allows us to correctly define its inverse fuction F−1X.
Then, we can generate random numbers whose distribution is fX, as follows:
- Generate a random number u between 0 and 1 .
- Calculate the unique value F−1X(u).
- Theorem: Let X,Y,U be random variables such that U∼Uniform(0,1) and Y=F−1X(U). Then, the CDF of Y is FX.
Examples:
- Generate Gaussian random numbers with mean μ and
variance σ2.
- The CDF of the ideal distribution is FX(x)=Φ(x−μσ).
- The transformation becomes F−1X(U)=σΦ−1(U)+μ.
- Generate exponential random numbers with parameter λ.
- The CDF of the ideal distribution is FX(x)=1−e−λx.
- The transformation becomes F−1(U)=−1λlog(1−U)
- Generate Gaussian random numbers with mean μ and
variance σ2.