Actuarial Statistics · Basic univariate distributions and generating samples
Generating Random Samples Using the Inverse Transform Method
Updated 11 October 2026 · Fact-checked
The inverse transform method turns a uniform random number U on (0,1) into a sample from any distribution with CDF F. You set U = F(x) and solve for x, giving x = F⁻¹(U). For discrete variables, choose the smallest x with F(x) ≥ U. Pseudo-random uniforms come from a recurrence such as the congruential generator.
Understand Generating Random Samples: Inverse Transform Method
Simulation needs a source of randomness. Computers do not produce truly random numbers. They produce pseudo-random numbers: a fixed, repeatable sequence that behaves like independent draws from the uniform distribution on (0,1). You start from a seed and apply a recurrence. The most common exam example is the congruential generator: X(n+1) = (a × X(n) + c) mod m, and then U(n) = X(n) ÷ m. The sequence repeats after at most m steps, so m should be large. Using the same seed gives the same sequence, which is why simulations can be reproduced.
Once you have uniform numbers, you need to turn them into draws from the distribution you want. The inverse transform method does this. The key fact is that if U is uniform on (0,1) and F is a CDF with inverse F⁻¹, then X = F⁻¹(U) has CDF F. The reason is short: P(X ≤ x) = P(F⁻¹(U) ≤ x) = P(U ≤ F(x)) = F(x), because P(U ≤ u) = u for u in (0,1).
For a continuous distribution with a strictly increasing CDF, set u = F(x) and solve for x. For the exponential with rate λ, F(x) = 1 − e^(−λx). Setting u = 1 − e^(−λx) gives x = −ln(1 − u) ÷ λ. Since 1 − U is also uniform on (0,1), you may use x = −ln(u) ÷ λ. Either is acceptable if you say which you use and apply it consistently.
For a discrete distribution, the CDF is a step function, so you cannot solve u = F(x) exactly. Instead, list the cumulative probabilities. Return the smallest value x for which F(x) ≥ u. In effect you cut the interval (0,1) into pieces whose lengths equal the probabilities, and the piece that u falls in tells you the value.
The method works for any distribution, but it is only convenient when F⁻¹ has a closed form. If it does not (the normal distribution, for example), you need numerical inversion or another method, such as acceptance-rejection.
Key rules to remember
- Congruential generator
- X(n+1) = (a × X(n) + c) mod m; U(n) = X(n) ÷ m
- Seed X(0) is given. If c = 0 it is called multiplicative. Values of X lie in 0 to m − 1, so U lies in [0, 1).
- Inverse transform rule
- X = F⁻¹(U), U ~ Uniform(0,1)
- Then X has CDF F. Proof: P(X ≤ x) = P(U ≤ F(x)) = F(x).
- Discrete version
- X = smallest x such that F(x) ≥ U
- Use the cumulative probability table. Check the order of the values, from smallest to largest.
- Exponential(λ)
- x = −ln(1 − u) ÷ λ
- Also valid: x = −ln(u) ÷ λ, since 1 − U is uniform. λ is the rate, so the mean is 1/λ.
- Uniform(a, b)
- x = a + (b − a) × u
- A direct linear transform of u.
- Pareto(α, λ)
- F(x) = 1 − (λ ÷ (λ + x))^α, so x = λ × [(1 − u)^(−1/α) − 1]
- This is the two-parameter Pareto used in the IAI tables. Check the form of F given in the question.
- Weibull(c, γ)
- F(x) = 1 − exp(−c × x^γ), so x = [−ln(1 − u) ÷ c]^(1/γ)
- Check the parametrisation given in the question or in the Tables.
- Normal(μ, σ²)
- x = μ + σ × Φ⁻¹(u)
- Φ⁻¹ is read from the normal tables. There is no closed form.
How to solve Generating Random Samples: Inverse Transform Method questions
Use this method for any question that asks you to simulate values from a given distribution using uniform random numbers.
- 1Write down the distribution and its CDF F(x). Note whether it is discrete or continuous.
- 2If you are asked to generate the uniforms, apply the recurrence X(n+1) = (a × X(n) + c) mod m from the seed. Compute each step exactly and divide by m to get u.
- 3Continuous case: set u = F(x) and rearrange to make x the subject. This gives your formula x = F⁻¹(u).
- 4Discrete case: list the values in increasing order with their cumulative probabilities. Each value owns the interval from the previous cumulative probability up to its own.
- 5Substitute each given u into your formula or table. For the discrete case, pick the smallest x with F(x) ≥ u.
- 6Check that each answer is in the valid range (for example, x ≥ 0 for an exponential) and that the sample is consistent with the distribution.
- 7State the result clearly, with units and the number of decimal places asked for. If the question concerns an estimate from many simulated values, state the estimate and note how it changes with the number of simulations.
Quickest way: Invert once, then substitute
When to use it: Use this when the question gives you the u values and the CDF, and you only need the simulated numbers.
- For continuous F, derive x = F⁻¹(u) once and write it as a formula. Check it with u = 0 and u close to 1: x should run from the bottom of the range upward.
- For discrete F, write the cumulative column next to the values before touching any u.
- Compute each u in one line on your calculator. Keep at least four decimal places during working.
- For a congruential generator, do the multiplication, then subtract multiples of m. Do not use decimals until you divide by m at the end.
- Do a sanity check: a small u should give a small x, and a large u a large x.
Common mistakes in Generating Random Samples: Inverse Transform Method
Choosing the wrong value at the boundary in a discrete simulation, for example taking the largest x with F(x) ≤ u.
Students think of the intervals loosely and do not use the rule F(x) ≥ u.
Fix: Always use: the smallest x with F(x) ≥ u. Write the cumulative column and compare u to each entry from the top.
Forgetting to divide by m, so the 'uniform' number is a whole number such as 6 instead of 0.375.
The recurrence produces X values, and students put them straight into the inverse formula.
Fix: Compute u = X ÷ m every time. A uniform number must lie in (0,1). If yours does not, stop and check.
Mixing up rate and mean for the exponential, giving x = −mean × ln(1 − u) when a rate was given (or the reverse).
Both parametrisations are common, and the question wording is not read carefully.
Fix: Write whether λ is a rate or a mean. With rate λ, x = −ln(1 − u) ÷ λ. With mean μ, x = −μ × ln(1 − u).
Arithmetic errors in the mod step, for example computing 33 mod 16 as 7 or leaving a value above m.
Rushing, or subtracting m only once when more is needed.
Fix: Subtract the largest multiple of m that does not exceed the number. The result must be between 0 and m − 1.
Using ln(u) where ln(1 − u) is needed in a formula that is not symmetrical, such as in a Pareto or Weibull inverse, or mixing the two between questions.
Students memorise the exponential shortcut and apply it blindly.
Fix: Derive the inverse from F each time. Replacing 1 − u by u is valid only because 1 − U is also uniform, and you should say so if you do it.
Claiming the generated numbers are truly random or independent.
Students ignore that the sequence is deterministic.
Fix: Say 'pseudo-random'. The sequence is fixed by the seed and repeats after at most m terms, but it should pass statistical tests for uniformity and independence.
Worked examples
Example 1
A congruential generator is defined by X(n+1) = (5 × X(n) + 3) mod 16 with seed X(0) = 7. (a) Find U1, U2 and U3. (b) Use them to simulate three values from an exponential distribution with rate 0.1, using x = −ln(1 − u) ÷ λ.
Show the solution
- X1 = (5 × 7 + 3) mod 16 = 38 mod 16 = 6, since 38 − 32 = 6. So U1 = 6 ÷ 16 = 0.375.
- X2 = (5 × 6 + 3) mod 16 = 33 mod 16 = 1. So U2 = 1 ÷ 16 = 0.0625.
- X3 = (5 × 1 + 3) mod 16 = 8. So U3 = 8 ÷ 16 = 0.5.
- For the exponential, F(x) = 1 − e^(−0.1x). Setting u = F(x) gives x = −ln(1 − u) ÷ 0.1 = −10 × ln(1 − u).
- u = 0.375: ln(0.625) = −0.4700, so x = 4.700.
- u = 0.0625: ln(0.9375) = −0.06454, so x = 0.645.
- u = 0.5: ln(0.5) = −0.6931, so x = 6.931.
Answer: U = 0.375, 0.0625, 0.5. The simulated exponential values are approximately 4.70, 0.645 and 6.93.
Example 2
A random variable X takes the values 1, 2, 3 and 4 with probabilities 0.2, 0.3, 0.4 and 0.1 respectively. Using the inverse transform method, simulate X from the uniform numbers 0.15, 0.62, 0.91 and 0.47.
Show the solution
- Build the cumulative distribution: F(1) = 0.2, F(2) = 0.5, F(3) = 0.9, F(4) = 1.
- The rule is: X is the smallest value x with F(x) ≥ u. So 0 < u ≤ 0.2 gives 1, 0.2 < u ≤ 0.5 gives 2, 0.5 < u ≤ 0.9 gives 3, and 0.9 < u < 1 gives 4.
- u = 0.15 is at most 0.2, so X = 1.
- u = 0.62 is above F(2) = 0.5 and at most F(3) = 0.9, so X = 3.
- u = 0.91 is above F(3) = 0.9, so X = 4.
- u = 0.47 is above F(1) = 0.2 and at most F(2) = 0.5, so X = 2.
Answer: The simulated values are 1, 3, 4 and 2.
Exam tips
- Show the inversion step in full: write F(x), set it equal to u, and solve. Marks are usually given for the formula x = F⁻¹(u) as well as the numbers.
- In a congruential generator question, show each X(n) value and each division by m. A wrong early value carries through, but clear working still earns method marks.
- For discrete questions, show the cumulative table. It makes the answer easy to check and shows you used the correct rule.
- Paper B or R tasks often use runif and the inverse CDF. Know that a seed (set.seed) makes the results reproducible, and be ready to comment on how the sample mean approaches the true mean as the number of simulations grows.
- If a question asks you to comment on the quality of a generator, mention period length, uniformity, independence of successive values and reproducibility from the seed.
Practice questions from Basic univariate distributions and generating samples
- Claim sizes X follow a Gamma distribution with shape α = 4 and rate λ = 0.02 per rupee thousand. Claims are scaled to Y = 3X (a change of un…
- A random variable X has cumulative distribution function F(x) = 1 - e^(-0.05x) for x > 0. Using the inverse transform method, a Uniform(0,1)…
- A call centre in Pune receives calls that follow a Poisson distribution with mean 4 per hour. What is the probability that exactly 2 calls a…
- A loss X is lognormal with parameters μ = 5 and σ² = 0.64, meaning ln X is Normal(μ, σ²). What is E[X]?
- A random number U is uniform on (0,1). To generate an exponential claim-interval with mean 5 days by the inverse transform method, which tra…
Generating Random Samples: Inverse Transform Method: frequently asked questions
Why does the inverse transform method work?
If U is uniform on (0,1), then P(U ≤ F(x)) = F(x). So the variable X = F⁻¹(U) satisfies P(X ≤ x) = F(x), which is exactly the CDF you want. This holds for any CDF if you use the generalised inverse, which is the smallest x with F(x) ≥ u.
How do I simulate an exponential random variable using uniform numbers?
Take a uniform number u and compute x = −ln(1 − u) ÷ λ, where λ is the rate. You can also use x = −ln(u) ÷ λ, because 1 − U is also uniform. The mean of the result is 1/λ.
How do I generate values from a discrete distribution?
Write the values in increasing order with their cumulative probabilities. For each uniform number u, return the smallest value whose cumulative probability is at least u. This is the same as splitting (0,1) into intervals whose lengths are the probabilities.
What is the congruential method for pseudo-random numbers?
It is the recurrence X(n+1) = (a × X(n) + c) mod m, starting from a seed X(0). You divide each X by m to get a number between 0 and 1. The sequence is fixed by the seed and repeats after at most m terms.
Can I use the inverse transform method for the normal distribution?
Yes, in principle: x = μ + σ × Φ⁻¹(u). But Φ⁻¹ has no closed form, so you need tables or numerical routines. This is why other methods, such as acceptance-rejection, are also studied.