When simulating [[Random Variable|random variables]], we want to draw a random sample $x$ of $X$, that comes from a specified distribution (e.g. [[Exponential Distribution]]).
However, computers typically generate random numbers $u$ from a [[Continuous Uniform Distribution]] in the interval $[0,1]$. To simulate a random variable $X$ from a desired distribution, we need to transform $u$ into a value that follows that target distribution.
![[simulation-of-distribution.png|center|400]]
## Inverse Transform Sampling
This method leverages the [[Cumulative Density Function]] to map uniformly distributed random variables to the desired distribution.
1. The CDF $F_X(x)$ of a distribution maps all $x$-values to $u \in [0,1]$.
2. Now we go the opposite direction, from $u$ $\in [0,1]$ to an $x$-value. Going the opposite direction (i.e. flipping input with output) means to take the the inverse $F^{-1}_X(x)$.
3. When a CDF is strictly [[Monotonicity|monotonic]], then the inverse CDF will always lead to a unique result, and is therefore applicable.
![[inverse-cdf.png|center|300]]
**Example:**
1. Calculate the inverse of $F_X(x) = 1-e^{-x}$.
2. Get a number $u$ from the random number generator
3. Apply $u$ to the inverse CDF to obtain $x$
$
\begin{align}
u&=1-e^{-x} \\
e^{-x}&=1-u \\
-x &= \log(1-u) \\
x &= -\log(1-u)
\end{align}
$