inverse-transform sampling
Your generator only knows how to give you uniform numbers — fractions spread evenly between 0 and 1, like a perfectly fair spinner. But your simulation needs numbers from some OTHER shape: an exponential, a normal, a custom distribution. Inverse-transform sampling is the clean trick that bends a uniform number into any distribution you want, as long as you can invert that distribution's cumulative function.
The recipe is three words long: U in, X out. Take the target distribution's cumulative distribution function F(x) = P(X <= x), which rises from 0 to 1. Draw a uniform u in [0, 1), then solve F(x) = u for x — that is, set X = F^{-1}(u), the inverse CDF (also called the quantile function). The magic is that X then has exactly the distribution F. Intuitively, F^{-1} stretches the uniform line so that more uniform mass lands where the target wants more probability: regions where F climbs steeply (high density) get a wide slice of the [0, 1) input, so points pile up there. For the exponential with rate lambda, F(x) = 1 - e^(-lambda x) inverts to X = -ln(1 - u) / lambda, a one-line sampler.
It is exact and elegant, and it is the gold standard whenever the inverse CDF is available in closed form or cheaply computable (exponential, Cauchy, geometric, any discrete table via a cumulative search). The honest limitation is the 'as long as' clause: for many important distributions — the normal being the headline example — F has no closed-form inverse, so plain inversion needs a numerical root-find or a special-function evaluation per sample, which can be slow. That is exactly why dedicated tricks like the Box-Muller transform exist for the normal, and why rejection sampling is the fallback when F is awkward.
To sample an exponential lifetime with mean 5 (rate lambda = 1/5): draw u = 0.3, compute X = -ln(1 - 0.3) / (1/5) = -5 * ln(0.7) = 1.78. Draw u = 0.9, get X = -5 * ln(0.1) = 11.5. Small u gives short lifetimes, u near 1 gives long ones — exactly the exponential's skew.
Feed a uniform number through the inverse CDF and out comes the target distribution.
Inversion needs the inverse CDF, which many distributions (notably the normal) lack in closed form. When F^{-1} is only available numerically, each sample costs a root-find — fine for a few draws, costly for millions.