Uniform Distribution Calculator

Discrete or continuous uniform on [a, b] — probabilities, mean and variance, with a shaded PDF/PMF chart and show/hide step-by-step working.

What is a uniform distribution?

A uniform distribution is the simplest kind of probability distribution: every outcome in a specified range is equally likely. There are two flavours — one for a finite list of values (like a fair die) and one for a continuous interval (like a random arrival time within an hour).

A fair six-sided die is the classic discrete uniform: each face 1–6 has probability 1/6, and the mean of the roll is (1 + 6)/2 = 3.5. A random second within a given hour is the classic continuous uniform: every instant in the 3600-second window is equally likely, and the mean arrival time is exactly halfway through.

The uniform distribution, piece by piece

Discrete uniform — every outcome equally likely

When the sample space is a finite list of integers {a, a+1, …, b}, every value has the same probability. Divide 1 by the count of outcomes n = b − a + 1 and you have P(X = k) for every k in the range.

P(X = k)
= 1 / n
n = b − a + 1
nnumber of integer outcomes·a, binclusive endpoints of the range
123456P(X = k) = 1/6 for each k
Example
Given
Fair die: a = 1
b = 6
Substitute
n = 6 − 1 + 1
= 6
so P(X = 4)
= 1/6
Answer
≈ 0.1667 (16.67%)

Continuous uniform — flat density on [a, b]

For a continuous range the probability of any single point is 0. Instead, probability is the fraction of the length [a, b] that your sub-interval [c, d] covers. The density f(x) = 1/(b − a) is constant across the whole support.

P(c ≤ X ≤ d) = (d − c) / (b − a)
b − alength of the full support·d − clength of the sub-interval you're asking about
abcdf(x) = 1/(b − a)
Example
Given
Arrival in 0–60 min
window 10–25 min
Substitute
(25 − 10) / (60 − 0) = 15/60
Answer
= 0.25 (25%)

Mean — the midpoint

Because every outcome carries equal weight, the mean is simply the middle of the range. The same formula works for the discrete and continuous case.

μ = (a + b) / 2
a, bendpoints of the range
abμ = (a + b) / 2
Example
Given
Uniform on [0, 60] minutes
Substitute
(0 + 60) / 2
Answer
μ = 30 minutes

Variance — how wide is the range?

A wider support means a larger variance. The two formulas are different: discrete uses the integer count n, continuous uses the length b − a directly.

Discrete: σ² = (n² − 1) / 12
Continuous: σ² = (b − a)² / 12
ninteger count b − a + 1 (discrete)·b − arange length (continuous)
narrow → small σ²wide → larger σ²
Example
Given
Fair die (n = 6)
Substitute
(6² − 1) / 12 = 35/12
Answer
σ² ≈ 2.9167, σ ≈ 1.708

Common mistakes

  • Using (b − a)²/12 for a discrete range. The discrete formula is (n² − 1)/12 with n = b − a + 1. For a fair die that's 35/12, not 25/12.
  • Forgetting the +1 in the count. There are b − a + 1 integers in {a, …, b}, not b − a — the interval includes both endpoints.
  • Treating P(X = x) as non-zero for a continuous uniform. A single point has probability 0; only intervals do. Use P(c ≤ X ≤ d).
  • Not clipping [c, d] to [a, b]. If your sub-interval pokes outside the support, only the overlap contributes — this calculator clips automatically.

Features of this calculator

  • Toggle between discrete and continuous uniform in a single tool.
  • Discrete mode: P(X = x) for any integer, plus n, mean (a+b)/2 and variance (n² − 1)/12.
  • Continuous mode: P(c ≤ X ≤ d) = (d − c)/(b − a), density f(x) = 1/(b − a), mean and variance (b − a)²/12.
  • Automatic clipping when [c, d] extends beyond [a, b] — only the overlap counts.
  • Shaded PDF/PMF diagram — flat bars for discrete, a rectangle with the sub-interval highlighted for continuous.
  • Show/hide step-by-step working with your own numbers substituted into every formula.
  • Copy the summary as text or download the result panel as a PNG.

Frequently asked questions

+Why is the variance of a fair die 35/12, not 25/12?

Because n = 6 (six equally likely faces), not 5. The discrete formula is (n² − 1)/12 = (36 − 1)/12 = 35/12 ≈ 2.917.

+Can a and b be negative?

Yes — the formulas only care about b − a. Uniform(−10, 10) has mean 0 and variance 400/12 ≈ 33.33.

+What if a = b?

The distribution collapses to a single value. Discrete: n = 1 and P(X = a) = 1. Continuous: it's a degenerate point, not a valid uniform — this calculator requires b > a for continuous mode.

+Is Uniform(0, 1) special?

It's the standard uniform — the default output of most random-number generators, and the building block for sampling from any other distribution via the inverse-CDF method.

+How is this related to the exponential distribution?

They're not the same shape at all — exponential is skewed with a heavy right tail. But both are common models for waiting times: uniform when arrivals are equally likely across a window, exponential when they follow a memoryless Poisson process.

+Can I use this for a random number generator's output?

Yes. If you sample a random integer from a to b inclusive, that's discrete uniform. If you sample a random real in [a, b], that's continuous uniform — use this tool to reason about the probability of landing in any sub-range.

Related calculators