Why Exponential Sampling Requires Care
The exponential distribution is a useful model for a nonnegative waiting time or loss amount when a constant rate is appropriate. In simulation, the task is to convert a uniform random number into a value with the desired exponential distribution. The calculation is short, but several details matter: the rate and scale parameterizations use reciprocal parameters, the logarithm is negative for inputs between zero and one, and the parameter’s units must match the quantity being generated.
This tutorial derives the transformation, shows how to use both parameterizations, and explains checks that help detect errors. It is aligned with the SOA Exam ASTAM (Advanced Short-Term Actuarial Mathematics) syllabus.
The same distribution can be described by its scale \(\theta=1/\lambda\). In this parameterization the density is \(f_X(x)=\frac{1}{\theta}e^{-x/\theta}\), and the scale has the same units as \(X\). The scale is not the rate: increasing the rate makes typical observations smaller, while increasing the scale makes them larger.
Deriving the Inverse-Transform Formula
Let \(U\) be uniform on \((0,1)\). The inverse-transform method chooses \(X\) so that its cumulative distribution function at \(X\) equals \(U\). For the exponential distribution, solve \(u=F_X(x)\) for \(x\):
Consequently, one exponential observation can be generated by drawing a uniform value \(u\) and applying the inverse cumulative distribution function. Replacing \(1/\lambda\) by \(\theta\) gives the scale form of the same formula. Since \(1-U\) is also uniform on \((0,1)\), the equivalent expression \(-\ln(U)/\lambda\) has the same distribution.
The derivation also verifies why the transformation works. For \(x\ge 0\), using \(X=-\ln(1-U)/\lambda\),
The last equality follows because the probability that a uniform value on \((0,1)\) is at most a number \(c\) in that interval is \(c\). The resulting cumulative distribution function is exactly the exponential cumulative distribution function. For \(x<0\), \(P(X\le x)=0\), as required by the nonnegative support.
Units, Mean, and Tail Checks
A generated value should have the same units as the quantity being simulated. If \(X\) is measured in days, \(\lambda\) is measured per day; if it is measured in thousands of dollars, \(\lambda\) is measured per thousand dollars. In the scale parameterization, \(\theta\) is expressed directly in days or thousands of dollars. A mismatch in units changes the simulated distribution even if the arithmetic is otherwise correct.
The mean provides a useful independent check. From the density, integration by parts gives
The boundary term is zero: at \(x=0\), it is zero, and as \(x\) tends to infinity, \(xe^{-\lambda x}\) tends to zero for \(\lambda>0\). The remaining integral is \(1/\lambda\). This confirms that the mean is the scale \(\theta\). A single generated observation need not equal the mean, but an observation far below the scale is not surprising, and the scale should not be confused with an upper bound.
The survival function, or probability of exceeding a specified value \(x\ge 0\), is
This gives another check: larger \(x\) should have smaller exceedance probability. Also, when \(U\) is used in the inverse cumulative distribution formula, the generated value is the \(U\)-quantile: \(F_X(X)=U\). Its corresponding survival probability is \(1-U\).
Worked Example: Simulating a Waiting Time Using the Rate
A hypothetical service system models a waiting time \(X\), in days, by an exponential distribution with rate \(\lambda=0.25\) per day. A uniform input is \(U=0.80\). Generate the waiting time, state the model mean, and check the survival probability at the generated value. Round the final time to three decimal places and the probability to four decimal places.
Method. Use inverse-transform sampling with the rate form. Since the rate is \(0.25\) per day, the generated value will be in days.
Generated value.
Rounded to three decimal places, the simulated wait is 6.438 days. The mean is \(1/\lambda=1/0.25=4\) days. The simulated value exceeds the mean; that is possible and does not indicate an error.
Tail check. The survival probability at this value is
This agrees with \(1-U=0.20\), as expected for a value generated from the 80th percentile. The common mistake avoided here is using \(-\ln(0.80)/0.25\) while also claiming to use \(U\) as the cumulative probability. That expression uses \(U\) as a survival probability instead; it corresponds to the equivalent formula with the uniform input replaced by \(1-U\).
Using the Scale Parameter
When a model is stated in terms of its scale, use \(X=-\theta\ln(1-U)\), or first calculate the rate \(1/\theta\). Do not substitute a scale directly into a denominator intended for a rate. The following example also checks an exceedance probability at a fixed loss amount.
Worked Example: Simulating a Loss Using the Scale
A hypothetical coverage model uses an exponential loss \(X\), measured in thousands of dollars, with scale \(\theta=3\) thousand dollars. A uniform input is \(U=0.40\). Generate the loss, identify the corresponding rate and mean, and calculate the probability that a separate loss from this model exceeds 6 thousand dollars. Report the simulated loss in dollars to the nearest cent and the probability to four decimal places.
Method and parameter conversion. The rate is the reciprocal of the scale:
Use the scale form of inverse transformation. The generated loss, first expressed in thousands of dollars, is
Converting units gives \(1.5324768\times \$1{,}000=\$1{,}532.4768\), or \$1,532.48 to the nearest cent. The model mean is the scale, so it is 3 thousand dollars, or \$3,000.
Exceedance probability. The threshold of 6 thousand dollars is \(x=6\) in the model’s thousand-dollar units. Therefore,
The mean and units are consistent: the scale is expressed in thousands of dollars, and the rate is per thousand dollars. A common error is to use \(-\ln(0.60)/3\) as the sample. That divides by the scale, producing the wrong value and units; the correct scale formula multiplies by \(-3\).
Reading the Uniform Input Correctly
The complement in the inverse cumulative distribution formula is not optional. If the input \(U\) is interpreted as a cumulative probability, the generated value must satisfy \(F_X(X)=U\), so its survival probability must be \(1-U\). An equivalent construction starts with a uniform value representing the survival probability and uses \(-\ln(U)/\lambda\). The two constructions have the same distribution, but the interpretation of the input differs.
This distinction is especially important when a problem supplies a high uniform value. In the cumulative-probability form, a high \(U\) generates a high quantile. In the survival-probability form, a low input generates a large value. Both are consistent with an exponential law when used as stated.
Worked Example: Upper-Tail Input and Quantile Check
A hypothetical equipment-repair duration \(X\), measured in months, has exponential rate \(\lambda=0.10\) per month. A simulation uses cumulative-probability input \(U=0.95\). Generate the duration, determine whether it is above or below 30 months, and verify that conclusion using the model’s tail probability. Round the duration to three decimals and probabilities to four decimals.
Method. Since the input is specified as a cumulative-probability input, use \(X=-\ln(1-U)/\lambda\):
The simulated duration is 29.957 months, which is below 30 months. To verify, the probability of exceeding 30 months is
Thus, \(P(X\le 30)=1-0.0498=0.9502\). The generated value is just below 30 months and has cumulative probability \(0.95\), consistent with that check. The common mistake avoided is replacing \(1-U=0.05\) with \(U=0.95\) inside the logarithm while still treating \(U\) as a cumulative probability. That would generate a small value, the opposite tail from the one intended.
Implementation Details and Exam Traps
For exact continuous uniform inputs, \(U\) lies strictly between zero and one, and both inverse-transform expressions are well-defined. Computer generators often use a specified finite set of values, sometimes including zero but excluding one. In that case, \(-\ln(U)/\lambda\) is undefined at \(U=0\), whereas \(-\ln(1-U)/\lambda\) is finite at zero and returns zero. A simulation implementation should follow the generator’s endpoint convention and avoid applying a logarithm to zero. An exact continuous model assigns probability zero to either endpoint, but a finite computational generator can produce endpoint values by design.
The following checks are useful when solving or implementing a problem:
- Check the parameter meaning. If the problem gives a rate, divide the negative logarithm by \(\lambda\). If it gives a scale, multiply the negative logarithm by \(\theta\).
- Check the input interpretation. For a cumulative-probability input, use \(1-U\) inside the logarithm. For a survival-probability input, \(-\ln(U)/\lambda\) is appropriate.
- Check units. The output has the same units as \(1/\lambda\) or \(\theta\). Do not mix, for example, a rate per month with a time measured in years without conversion.
- Check the mean. A rate of \(\lambda\) implies mean \(1/\lambda\); a scale of \(\theta\) implies mean \(\theta\).
- Check the tail. At a generated cumulative-probability input \(U\), the exceedance probability at the generated value is \(1-U\).
The formulas apply to an exponential model with positive rate, equivalently positive scale, and nonnegative support. They do not turn an arbitrary uniform input into an exponential value with a different rate or scale unless the parameter used in the transformation is changed accordingly. They also do not assert that every real loss is exponential: the distribution is a modeling assumption, and sampling implements that assumption rather than validating it.
Check Your Understanding
For each problem, identify the parameterization before applying the transformation. Answers use the rounding requested or stated in the problem.
- A hypothetical call-center waiting time is exponential with rate \(0.50\) per hour. Using cumulative-probability input \(U=0.30\), generate the wait in hours to four decimal places and state the model mean. (Answer: \(0.7133\) hours; mean \(2\) hours.)
- A hypothetical repair cost is exponential with scale \(\theta=4\) days. For \(U=0.75\), calculate the generated duration to four decimal places and give the corresponding rate. (Answer: \(5.5452\) days; rate \(0.25\) per day.)
- A hypothetical loss in thousands of dollars has rate \(2\) per thousand dollars. For \(U=0.90\), calculate the generated loss in thousands of dollars to four decimal places and the model probability of exceeding 1 thousand dollars. (Answer: \(1.1513\) thousand dollars; \(0.1353\).)
- A hypothetical event time is exponential with rate \(0.04\) per hour. Using cumulative-probability input \(U=0.02\), calculate the generated time to four decimal places and state whether it is above or below the mean. (Answer: \(0.5051\) hours; below the mean of \(25\) hours.)
- A hypothetical duration has scale \(\theta=5\) hours. Find its 80th percentile and the probability that a separate duration exceeds 10 hours. Give the percentile to four decimals and the probability to four decimals. (Answer: \(8.0472\) hours; \(0.1353\).)