Expected annual loss and its distribution under mitigation.
Risk is probability times consequence. With hazards i of annual probability pi and severity si, the expected annual loss is E[L] = Σ pi si and, as hazards are independent, the variance is Var[L] = Σ pi(1-pi) si2.
Preventive measures scale the probability: pi → pi(1-m). The hazards are ranked by pisi and the top k are treated first, the standard prioritisation rule. The histogram shows simulated annual loss; the tail (95th percentile, "value at risk") often matters more than the mean because rare big events dominate it.
Hazards are independent, probabilities and severities are illustrative round numbers, and mitigation has no cost. Real assessments add correlations, uncertainty in the inputs and the price of controls.
The simulated mean annual loss is compared to the exact Σpisi; agreement must lie within four standard errors √(Var/Y). The result is shown live under the chart and turns red if the agreement fails.
All random draws come from a seeded 32-bit generator (mulberry32) and Gaussian variates from the Box-Muller transform, so a given seed always produces the same sample on every device; Re-run random seed advances the seed deterministically. Deterministic curves are evaluated on a fixed grid and integrated, where needed, with a fixed-step fourth-order Runge-Kutta scheme whose local error scales with the fifth power of the step; the step sizes used here keep the error far below the drawn line width.
The tiles under the chart are recomputed on every slider move. Quantities labelled exact or analytic come from a closed-form expression; quantities labelled simulated come from the random sample and fluctuate around the exact value by an amount that shrinks as the sample size grows (roughly as one over the square root of the sample size). The green or red box is the automated agreement test between the two.
This page is an educational model, not a decision tool. It is meant to build intuition for how a handful of parameters shape an outcome and how a stated formula can be checked against an independent numerical experiment. Numbers are illustrative unless a unit is given, and results must not be used for real engineering, medical, financial or legal decisions. If you notice a result that contradicts the stated formula, the built-in check is the first place to look: it is designed to fail loudly instead of hiding a disagreement, and a failing check on a sensible parameter set would be a bug worth reporting.
Why does the simulated value never match the exact one perfectly? Because a finite random sample has sampling error; the check box tests that the difference is no larger than four standard errors, which a correct model fails only about once in sixteen thousand runs.
Why are some sliders limited to a narrow range? Outside those ranges the formula is still valid mathematically but the plain-language interpretation stops making sense, or the chart would become unreadable.
Can I embed or share a state? The page keeps no hidden state: the sliders, the seed and the formulas fully determine every number you see, so a screenshot of the sliders is enough to reproduce a result.
Does the chart work on a phone? Yes. The canvas resizes with its container, scales to the device pixel ratio (capped at 2 for smooth drawing), and the controls stack above the chart on narrow screens.