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.
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.
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.
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.
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.