A television needs repairs at rate λ per year; the gaps between repairs are exponential, so the number of repairs in the warranty period is Poisson. Each repair costs a normal amount. The bars show the total repair bills of simulated customers (relative frequency; the gold bar at the left is the share with no repair at all). The pink curve is the exact law of the bill, a compound Poisson sum, scaled to the bars. Increase the number of simulated customers and the bars settle onto the curve; the table compares each simulated summary with its exact value and shows how large the simulation error is.
Each customer: draw exponential gaps with mean 1/λ until the total passes the warranty length, and for every gap that ends inside it draw one repair cost from Normal(μ, σ²). The exact values use the Poisson probabilities of the number of repairs and the normal law of a sum of k costs; a negative bill has negligible probability and is ignored.
code/ch04_special_distributions.py (simulate_warranty, warranty_exact).