From Uniform Variates to Random Outcomes
Many simulation tasks begin with a source of uniform random numbers and require samples from a different distribution. The inverse-transform method gives a direct construction: use a uniform variate to locate a probability level, then map that level to an outcome. For a finite set of categories, this means dividing the unit interval into pieces whose lengths are the category probabilities. For a continuous distribution, it means inverting its cumulative distribution function, with a generalized inverse when the CDF is not strictly increasing.
Work on a probability space \((\Omega,\mathcal{F},\mathbb{P})\). A random variable \(U\) is uniform on \((0,1)\) if \(\mathbb{P}(U\le u)=u\) for \(0\le u\le1\). This idealized source assigns probability zero to either endpoint. In computation, a pseudorandom generator typically returns one of finitely many values, and may include 0 or exclude 1; endpoint conventions therefore matter in code even though a continuous uniform variable hits any particular boundary with probability zero.
The Inverse-CDF Result
Proof. Fix \(x\in\mathbb{R}\) and \(u\in(0,1)\). If \(u\le F(x)\), then \(x\) belongs to the set \(\{y:F(y)\ge u\}\), so its infimum is at most \(x\). Conversely, suppose \(F^{-1}(u)\le x\). For each positive integer \(m\), the definition of infimum gives a point \(y_m\) with \(F(y_m)\ge u\) and \(y_m<F^{-1}(u)+1/m\le x+1/m\). Since a CDF is nondecreasing, \(F(x+1/m)\ge F(y_m)\ge u\). Right-continuity of \(F\) gives \(F(x)=\lim_{m\to\infty}F(x+1/m)\ge u\). Thus \(F^{-1}(u)\le x\) exactly when \(u\le F(x)\). Applying this equivalence to \(U\), \(\mathbb{P}(F^{-1}(U)\le x)=\mathbb{P}(U\le F(x))=F(x)\); the last equality follows from uniformity, including the cases \(F(x)=0\) and \(F(x)=1\). \(\square\)
The result does not require \(F\) to be continuous or strictly increasing. If \(F\) has a jump, a range of uniform values maps to the same outcome, producing the corresponding point mass. If \(F\) is flat over an interval, the generalized inverse selects the leftmost point at the required probability level. In practice, solving \(F(x)=u\) is appropriate only on a portion where that equation has a suitable solution; the generalized inverse states the rule without assuming a unique solution.
Categorical Outcomes
Suppose the possible outcomes are \(1,\ldots,r\), with probabilities \(p_1,\ldots,p_r\), where \(p_k\ge0\) and \(\sum_{k=1}^r p_k=1\). Define cumulative probabilities \(C_0=0\) and \(C_k=\sum_{\ell=1}^k p_\ell\). With a uniform variate \(U\in[0,1)\), choose the smallest \(k\) such that \(U<C_k\). Equivalently, assign category \(k\) to the interval \([C_{k-1},C_k)\). A category with probability zero has an empty interval and is never selected.
Proof. The event that category \(k\) is selected is \(C_{k-1}\le U<C_k\). For a uniform variable on \([0,1)\), the probability of an interval contained in \([0,1)\) is its length, so this event has probability \(C_k-C_{k-1}=p_k\). If \(p_k=0\), the interval is empty and both sides equal zero. The intervals cover \([0,1)\), because \(C_r=1\), and are disjoint under the stated endpoint convention. Therefore every possible uniform value selects exactly one category. \(\square\)
Worked Example: Selecting Among Three Categories
Let the outcomes be \(A,B,C\), with probabilities \(\tfrac12,\tfrac13,\tfrac16\). First check the probabilities: \(\tfrac12+\tfrac13+\tfrac16=\tfrac36+\tfrac26+\tfrac16=1\). The cumulative probabilities are \(C_1=\tfrac12\), \(C_2=\tfrac12+\tfrac13=\tfrac56\), and \(C_3=1\). Thus the intervals are \([0,\tfrac12)\) for \(A\), \([\tfrac12,\tfrac56)\) for \(B\), and \([\tfrac56,1)\) for \(C\).
For \(U=\tfrac14\), we have \(0\le\tfrac14<\tfrac12\), so select \(A\). For \(U=\tfrac12\), the first interval excludes its right endpoint and the second includes its left endpoint, so select \(B\). For \(U=\tfrac{11}{12}\), \(\tfrac56=\tfrac{10}{12}<\tfrac{11}{12}<1\), so select \(C\).
Check: The interval lengths are \(\tfrac12-0=\tfrac12\), \(\tfrac56-\tfrac12=\tfrac13\), and \(1-\tfrac56=\tfrac16\), exactly the three specified probabilities. The intervals are disjoint and their lengths sum to \(1\).
Continuous Distributions by Inversion
For a continuous distribution with an invertible CDF, the theorem often yields a direct formula. For example, if an exponential variable has rate \(\lambda>0\), its CDF for \(x\ge0\) is \(F(x)=1-e^{-\lambda x}\). Solving \(u=1-e^{-\lambda x}\) gives \(x=-\log(1-u)/\lambda\). The condition \(\lambda>0\) is needed for this to be an exponential rate and for the formula to define the stated distribution. When a CDF is piecewise-defined, identify the probability range for each piece before solving; then check that each result lies in the piece where its formula was used.
Worked Example: Generating an Exponential Value
Let \(F(x)=1-e^{-2x}\) for \(x\ge0\), with \(F(x)=0\) for \(x<0\). For a uniform value \(U=\tfrac34\), solve \(F(x)=\tfrac34\): \(1-e^{-2x}=\tfrac34\), so \(e^{-2x}=\tfrac14\), \(-2x=\log(\tfrac14)=-\log 4\), and \(x=\tfrac12\log 4=\log 2\). This value is nonnegative, as required by the support.
Check: Substituting \(x=\log 2\) gives \(F(\log 2)=1-e^{-2\log 2}=1-e^{-\log 4}=1-\tfrac14=\tfrac34\). Thus the proposed value is at the required CDF level.
Worked Example: Inverting a Piecewise CDF
Consider the density \(f(x)=4x\) for \(0\le x\le\tfrac12\), \(f(x)=4(1-x)\) for \(\tfrac12<x\le1\), and zero otherwise. Its total integral is \(\int_0^{1/2}4x\,dx+\int_{1/2}^1 4(1-x)\,dx=\tfrac12+\tfrac12=1\). Integrating gives \(F(x)=2x^2\) on \([0,\tfrac12]\), and \(F(x)=1-2(1-x)^2\) on \((\tfrac12,1]\). At the join, the first expression gives \(2(\tfrac12)^2=\tfrac12\), and the second gives \(1-2(\tfrac12)^2=\tfrac12\).
For \(U=\tfrac18\), the probability level is at most \(\tfrac12\), so use \(2x^2=\tfrac18\). Then \(x^2=\tfrac1{16}\), and the solution in \([0,\tfrac12]\) is \(x=\tfrac14\). For \(U=\tfrac78\), use the upper branch: \(1-2(1-x)^2=\tfrac78\). Hence \(2(1-x)^2=\tfrac18\), \((1-x)^2=\tfrac1{16}\), and the solution in \((\tfrac12,1]\) is \(x=\tfrac34\).
Check: \(F(\tfrac14)=2(\tfrac14)^2=\tfrac18\). Also \(F(\tfrac34)=1-2(1-\tfrac34)^2=1-2(\tfrac14)^2=1-\tfrac18=\tfrac78\). Both solutions lie in the branch used to obtain them.
Endpoints, Precision, and a Common Error
The interval convention is part of a categorical algorithm, not a cosmetic choice. For a continuous uniform variable, the probability of landing exactly on a cumulative boundary is zero, so changing the assignment at finitely many boundaries does not change the ideal distribution. A finite-precision generator can, however, return a boundary exactly. Use one comparison rule consistently: for values in \([0,1)\), select the first \(k\) with \(U<C_k\). Check that the probabilities are nonnegative and sum to one before forming the cumulative probabilities. If rounding makes the final cumulative value less than one, a generator value near one may not be assigned any category.
Common mistake: mixing endpoint conventions. In the three-category example, \(C_1=\tfrac12\). If \(U=\tfrac12\), the correct \([C_{k-1},C_k)\) convention selects \(B\), because \(\tfrac12\) is excluded from \(A\)'s interval and included in \(B\)'s. The incorrect calculation “select the first \(k\) with \(U\le C_k\)” selects \(A\), since \(\tfrac12\le C_1\). That comparison instead assigns a boundary to the preceding interval. Although this event has probability zero for an ideal continuous uniform variable, inconsistent comparisons can produce errors with finite-precision inputs or make repeated calculations disagree.
For continuous inversion, endpoints also require attention. The exponential formula \(-\log(1-U)/\lambda\) is defined at \(U=0\), giving zero, but it is undefined at \(U=1\), where the limiting quantile is infinite. If software can return 1 because of rounding, passing that value directly to the logarithm is not valid. Likewise, rounding a uniform input before inversion can move it across a CDF threshold or onto an endpoint. Keep adequate precision, use the exact interval or branch tests in the algorithm, and handle any endpoint that the random-number generator can actually return.
Inverse transform sampling is useful because it separates the source of randomness from the distribution being simulated. One uniform variate can generate a categorical decision or a continuous draw, and the CDF provides a direct check: a proposed value \(x\) should correspond to the input probability level through \(F(x)\), with the generalized inverse handling jumps and non-unique inverse levels. The method is especially convenient when the CDF can be inverted exactly or numerically. It is not a license to use an algebraic inverse outside its support or the branch from which it was derived.
Check Your Understanding
For each question, state the interval or CDF calculation used, and check the result by substitution.
- For category probabilities \(\tfrac14,\tfrac12,\tfrac14\), write the cumulative probabilities and determine the category selected by \(U=\tfrac34\) under the \([C_{k-1},C_k)\) convention.
- If \(F(x)=1-e^{-3x}\) for \(x\ge0\), find the inverse-transform value for \(U=\tfrac12\) and verify its CDF level.
- Explain why a generalized inverse is needed when a CDF has a jump or a flat interval.
- For a categorical sampler using \(U\in[0,1)\), explain why “first cumulative probability greater than or equal to \(U\)” is not consistent with the interval convention at an exact boundary.
- What endpoint problem can occur if a generator returns \(U=1\) and the target is an exponential distribution?