Back to the blog

Monte Carlo with Any Distribution: Why It Works and How to Do It

When comparing a Monte Carlo simulation with Normal vs. Lognormal distribution using typical ball mill parameters (mean 14 kWh/t, σ 2 kWh/t), the curves nearly overlap. The obvious question is: "if the results are so similar, where is the problem with assuming normality?"

The answer has two parts and this article addresses both:

  1. Why two distributions with the same mean and σ can look nearly identical (spoiler: coefficient of variation too low).
  2. Why Monte Carlo works with any distribution — not just normal — and how to implement that flexibility in Python.

We'll see three cases where the difference between assuming normal and using the correct distribution is not marginal, it is decisive.


1. Why Can Two Distributions Look So Similar?

When a variable has mean 14 kWh/t and standard deviation 2 kWh/t, its coefficient of variation (CV = σ/μ) is only 14%. For low CV values, the lognormal is practically indistinguishable from the normal.

The following code shows this directly:

import numpy as np
import matplotlib.pyplot as plt

rng = np.random.default_rng(42)
N = 50_000
mu = 100  # keep the mean fixed

fig, axes = plt.subplots(1, 3, figsize=(15, 4))
for ax, cv in zip(axes, [0.15, 0.50, 1.00]):
    sigma = cv * mu
    # Equivalent lognormal parameters
    mu_log = np.log(mu**2 / np.sqrt(mu**2 + sigma**2))
    sigma_log = np.sqrt(np.log(1 + (sigma/mu)**2))

    norm = rng.normal(mu, sigma, N)
    logn = rng.lognormal(mu_log, sigma_log, N)

    ax.hist(norm, bins=80, alpha=0.5, density=True, label="Normal")
    ax.hist(logn, bins=80, alpha=0.5, density=True, label="Lognormal")
    ax.set_title(f"CV = {cv:.2f}")
    ax.legend()
plt.tight_layout()
plt.show()

Normal vs. Lognormal at three CV levels

  • CV = 0.15 → nearly identical (the typical regime of controlled plant variables).
  • CV = 0.50 → they separate; the lognormal shows right tail.
  • CV = 1.00 → radically different distributions; the normal even generates negative values.

Operational conclusion: the choice of distribution matters when variability is high relative to the mean. Process variables with CV > 30% (reagent consumption with upsets, time to failure, ore grades) are in that regime and assuming normality produces significant errors in the percentiles.


2. The Principle: Monte Carlo Does Not Require Any Distribution

The Monte Carlo method only requires two things:

  1. Ability to sample randomly from the distribution of each input variable.
  2. Ability to evaluate the deterministic model at each sample.

That's it. There is no theorem that forces you to use normal. Theory does not distinguish between normal, Weibull, beta, bimodal, empirical, or a custom mixture. As long as you have a sampler, Monte Carlo works.

The confusion comes from three places:

  • Normal is the easiest distribution to explain in introductory courses.
  • The Central Limit Theorem appears frequently in statistics, and is overgeneralized incorrectly.
  • Excel historically offered only NORM.INV easily, which propagated the habit.

Python breaks that limitation: you can sample from practically any distribution with a single line of code.


3. Four Ways to Sample from Non-Normal Distributions

3.1 NumPy Direct Generators

numpy.random.Generator already includes a dozen ready-to-use distributions:

rng = np.random.default_rng(42)
N = 10_000

samples_normal       = rng.normal(loc=100, scale=15, size=N)
samples_lognormal    = rng.lognormal(mean=4.5, sigma=0.5, size=N)
samples_exponential  = rng.exponential(scale=2000, size=N)
samples_weibull      = rng.weibull(a=1.8, size=N) * 3000
samples_gamma        = rng.gamma(shape=2, scale=1.5, size=N)
samples_beta         = rng.beta(a=18, b=2, size=N)
samples_triangular   = rng.triangular(left=80, mode=100, right=150, size=N)
samples_uniform      = rng.uniform(low=0.1, high=0.9, size=N)
samples_poisson      = rng.poisson(lam=5, size=N)

Each call returns a vector of N samples. That's all Monte Carlo needs.

3.2 Universal Catalog of scipy.stats

SciPy exposes more than 80 distributions with a uniform API: .rvs(..., size=N) samples:

from scipy import stats

# Two-parameter Weibull (shape k, scale λ)
samples_w = stats.weibull_min.rvs(c=1.5, scale=2000, size=N, random_state=rng)

# Beta for variables bounded in [0, 1]
samples_b = stats.beta.rvs(a=5, b=2, size=N, random_state=rng)

# Pareto distribution (heavy tails)
samples_p = stats.pareto.rvs(b=1.16, scale=50, size=N, random_state=rng)

# Student's t distribution (heavier tails than normal)
samples_t = stats.t.rvs(df=5, loc=100, scale=15, size=N, random_state=rng)

# Truncated normal (normal restricted to a physical range)
samples_nt = stats.truncnorm.rvs(a=-2, b=2, loc=100, scale=10, size=N, random_state=rng)

Same logic, different distribution. Monte Carlo is agnostic.

3.3 Inverse Transform: Any Custom Distribution

If the distribution you need is not in NumPy or SciPy, you can build it using the inverse transform method:

If U ~ Uniform(0,1) and F is the cumulative distribution function (CDF), then X = F⁻¹(U) has the desired distribution.

Example — Pareto distribution written "by hand":

# CDF: F(x) = 1 - (x_min / x)^alpha  for x >= x_min
# Inverse: x = x_min / (1 - u)^(1/alpha)

def sample_pareto(x_min, alpha, size, rng):
    u = rng.uniform(0, 1, size)
    return x_min / (1 - u)**(1/alpha)

samples = sample_pareto(x_min=10, alpha=1.5, size=N, rng=rng)

This works for any distribution for which you can write the inverse CDF. Very useful for engineering distributions that don't have a formal name.

The animation shows why it works, with that same Pareto (\(x_{min} = 10\), \(\alpha = 1.5\)):

Animation (needs JavaScript): each uniform u crosses to the CDF and drops to x = F⁻¹(u); with 2000 samples, the histogram follows the Pareto density.

3.4 Bootstrap: Sample Directly from Historical Data

If you don't know what distribution you have but have real historical data, you don't need to fit anything — sample directly from the data:

# Historical collector consumption data (example)
historical_data = np.array([142, 138, 155, 161, 150, 147, 310, 145, 152, 148,
                             139, 159, 143, 280, 151, 146, 154, 260, 149, 158])

samples = rng.choice(historical_data, size=N, replace=True)

This automatically captures any skewness, bimodality, or heavy tails that exist in the data, without assuming any form. The only requirement is to have enough representative historical data (typically n ≥ 50).


4. Case 1: Where the Difference IS Dramatic

Let's size a storage tank for a reagent whose historical consumption has:

  • Mean = 100 g/t
  • Standard deviation = 100 g/t (CV = 1.0)

We want the P99 of consumption to guarantee 99% stock coverage.

N = 100_000
mu, sigma = 100, 100

# Case A: assume Normal
x_norm = rng.normal(mu, sigma, N)
x_norm = np.clip(x_norm, 0, None)  # avoid negatives

# Case B: use Lognormal (same mean, same standard deviation)
mu_log = np.log(mu**2 / np.sqrt(mu**2 + sigma**2))
sigma_log = np.sqrt(np.log(1 + (sigma/mu)**2))
x_logn = rng.lognormal(mu_log, sigma_log, N)

print(f"Normal    → mean={x_norm.mean():.1f}, P95={np.percentile(x_norm,95):.1f}, "
      f"P99={np.percentile(x_norm,99):.1f}, P99.9={np.percentile(x_norm,99.9):.1f}")
print(f"Lognormal → mean={x_logn.mean():.1f}, P95={np.percentile(x_logn,95):.1f}, "
      f"P99={np.percentile(x_logn,99):.1f}, P99.9={np.percentile(x_logn,99.9):.1f}")

Typical result:

Metric Normal Lognormal Δ (%)
Mean 105.2 100.1 —
P95 266 284 +7%
P99 333 485 +46%
P99.9 410 810 +98%

The mean and standard deviation are equal by construction, but the lognormal predicts extreme events that are double at the P99.9. If you size the tank with the P99 assuming normal, the tank falls short 1% of the time by a considerable margin — and in an operation running 8,760 hours per year, that's 87 hours of downtime per year from lack of reagent.

With CV = 1.0, the story changes radically: the P99 difference between normal and lognormal is almost 50%, not marginal.


5. Case 2: Where Normal Makes NO SENSE from the Start

Let's predict the time to failure of liners in a mill. The standard reliability distribution is Weibull, not normal. Normal is not even a valid candidate because:

  • It allows negative times (impossible).
  • It has symmetric tails (component aging is fundamentally asymmetric).
# Typical liner parameters: Weibull shape k=2.5, scale λ=3500 h
from scipy import stats

N = 50_000
time_to_failure = stats.weibull_min.rvs(c=2.5, scale=3500, size=N, random_state=rng)

print(f"MTTF (mean): {time_to_failure.mean():.0f} h")
print(f"Median:      {np.median(time_to_failure):.0f} h")
print(f"P10:         {np.percentile(time_to_failure, 10):.0f} h")
print(f"P90:         {np.percentile(time_to_failure, 90):.0f} h")

# Probability of surviving 2000 hours
prob_surv_2000 = np.mean(time_to_failure > 2000)
print(f"P(failure > 2000 h) = {prob_surv_2000:.3f}")

This is pure Monte Carlo, without a normal in sight. The logic is identical to any other simulation: sample → propagate → analyze. Only the sampler changed.

We can extend to a simulation of annual mill availability:

def simulate_availability(n_years=10_000, hours_year=8760, rng=None):
    rng = rng or np.random.default_rng()
    hours_available = np.zeros(n_years)

    for i in range(n_years):
        t = 0
        hours_op = 0
        while t < hours_year:
            time_to_failure = stats.weibull_min.rvs(
                c=2.5, scale=3500, random_state=rng)
            time_to_repair = stats.lognorm.rvs(
                s=0.4, scale=24, random_state=rng)  # ~24 h ± asymmetric

            if t + time_to_failure >= hours_year:
                hours_op += hours_year - t
                break
            hours_op += time_to_failure
            t += time_to_failure + time_to_repair

        hours_available[i] = hours_op

    return hours_available / hours_year  # fractional availability

avail = simulate_availability(n_years=5000, rng=rng)
print(f"Mean availability: {avail.mean():.3f}")
print(f"P05 of availability: {np.percentile(avail, 5):.3f}")

Here Weibull (time to failure) and Lognormal (repair time) coexist in the same simulation. Neither is normal. Monte Carlo doesn't care.


6. Case 3: The Distribution Is Not Parametric — It's a Mixture

Sometimes the real phenomenon has no known statistical name. For example, a reagent is consumed:

  • 85% of the time in normal regime (standard operating mode)
  • 15% of the time in upset regime (mineral problems, low flotability, compensating with more reagent)

There's no single parametric distribution that describes this. It's a mixture (mixture model). Monte Carlo handles it directly:

def sample_consumption_mixture(N, rng):
    # Is this point in normal or upset regime?
    state = rng.uniform(0, 1, N) < 0.85   # 85% normal

    # Normal regime: around 150 g/t, low dispersion
    consumption_normal = rng.normal(150, 15, N)

    # Upset regime: around 280 g/t, more dispersion
    consumption_upset = rng.lognormal(np.log(280), 0.25, N)

    # Combine according to state
    return np.where(state, consumption_normal, consumption_upset)

consumptions = sample_consumption_mixture(100_000, rng)

print(f"Mean:  {consumptions.mean():.1f} g/t")
print(f"P50:   {np.percentile(consumptions, 50):.1f} g/t")
print(f"P95:   {np.percentile(consumptions, 95):.1f} g/t")
print(f"P99:   {np.percentile(consumptions, 99):.1f} g/t")

Bimodal distribution: normal + upsets

The histogram shows two modes — one around 150 and another around 280. No standard parametric distribution captures this; a forced normal here would give absurd results. But Monte Carlo simulation works without issue, because the only requirement is being able to generate samples.

More sophisticated variants of this same pattern:

  • Three or more regimes (normal / degraded / critical).
  • Regime probabilities that depend on other variables (head grade, time of day, season).
  • Direct bootstrap from historical data if you don't want to assume any form.

7. The General Pattern of Monte Carlo with Any Distribution

The recipe that encompasses all the previous cases:

def monte_carlo_generic(N, deterministic_model, input_generators, rng):
    """
    N                      : number of simulations
    deterministic_model    : function(dict_inputs) → output
    input_generators       : dict {variable_name: function(N, rng) → samples}
    """
    inputs = {name: gen(N, rng) for name, gen in input_generators.items()}
    outputs = np.zeros(N)
    for i in range(N):
        sample_i = {k: v[i] for k, v in inputs.items()}
        outputs[i] = deterministic_model(sample_i)
    return outputs

An example mixing all four sampling forms — normal, lognormal, Weibull, and empirical:

historical_grade_data = np.array([...])  # your historical grade series

generators = {
    "power":     lambda N, rng: rng.normal(500, 15, N),
    "wi":        lambda N, rng: rng.lognormal(np.log(14), 0.25, N),
    "t_failure": lambda N, rng: stats.weibull_min.rvs(c=2.5, scale=3500,
                                                       size=N, random_state=rng),
    "grade":     lambda N, rng: rng.choice(historical_grade_data, size=N, replace=True),
}

def my_model(x):
    # your business logic here — recovery, throughput, NPV, etc.
    return x["power"] * x["grade"] / x["wi"]

results = monte_carlo_generic(50_000, my_model, generators, rng)

No variable needs to be normal. That's the whole point of this article.


8. Conclusion

Monte Carlo is not tied to the normal distribution. It works with whatever you give it: normal, lognormal, Weibull, beta, gamma, triangular, Pareto, Student's t, mixtures, bootstrap from historical data, or custom distributions built by inverse transform.

Normality is a default choice when no better information is available — but in process engineering you almost always have better information, either from the physics of the phenomenon (reliability → Weibull) or from available historical data (MLE fit or direct bootstrap).

The robust Monte Carlo workflow is:

  1. Identify the distribution of each variable (fit + validation — covered in the previous article on distribution identification).
  2. Choose the correct generator according to the case: NumPy, SciPy, inverse transform, or bootstrap.
  3. Propagate through the deterministic model.
  4. Report percentiles, not just the mean.

If your data has high CV, is skewed, has frequent outliers, or comes from mixtures of regimes — assuming normality introduces errors that can be two digits in the extreme percentiles. In plant design, reagent inventories, or mechanical availability, that translates directly to unnecessary oversizing or dangerous undersizing.

Python offers the full toolbox to do it right. There's no technical excuse to keep assuming normal by default.

Back to the blog