The Continuous Uniform Distribution
Ask a computer to "pick a random number between 0 and 1" and it reaches for exactly one
distribution: the continuous uniform. It is the simplest continuous
distribution there is — and the most democratic. Every value in a chosen interval
[a, b] is equally likely; no stretch of the interval
is favoured over any other of the same length. There is no peak, no tail, no lopsidedness — just a
perfectly flat, level playing field from a to b.
Because it is so even-handed, it turns up wherever "we know the range but nothing more" is the
honest description: the fractional part of a rounding error, the position of a bus somewhere along a
timetable window, the raw output of a random-number generator. It is also the launch pad for
every other
random distribution a computer produces — feed uniform numbers through the right
transformation and out come normal, exponential, or any shape you like.
Unlike the normal
distribution, whose bell concentrates values near a centre, the uniform spreads its
chances out perfectly flatly. We write
X \sim U(a, b)
to say X is uniform on the interval from a to
b.
A flat density: how "equally likely" looks
For a continuous
distribution we describe chance with a probability density
f(x) — a curve whose area gives probability. "Every value
equally likely" forces that curve to be constant across
[a, b] and zero everywhere else:
f(x) = \begin{cases} \dfrac{1}{b - a}, & a \le x \le b, \\[4pt] 0, & \text{otherwise.} \end{cases}
Why the exact height \tfrac{1}{b-a}? Because the total area must
be 1 — some value certainly occurs. The graph is just a rectangle of width
(b - a) sitting on the interval, and a rectangle's area is width times
height. To make that area equal 1, the height has to be exactly
\tfrac{1}{b-a}. Widen the interval and the rectangle must get shorter;
narrow it and the rectangle must grow taller — always keeping its area pinned at one.
Now the magic simplification. Since the height is constant, the probability of landing in some
sub-interval [c, d] is just the area of a smaller rectangle — and that is
simply what fraction of the whole interval it covers:
P(c \le X \le d) = \frac{d - c}{b - a}.
Probability becomes a matter of measuring length. Half the interval carries half the probability; a
tenth of the interval carries a tenth. Nothing to integrate, nothing to look up — just "how big a
slice is it?"
See it — and shade a probability
The top panel is the flat density; the shaded rectangle is
P(c \le X \le d), and its area (printed above it) is exactly the fraction
of the interval it covers. The bottom panel is the running total — the
cumulative distribution F(x) = P(X \le x). Because chance
accumulates at a constant rate, that graph is a perfectly straight line climbing
from 0 at a to 1 at
b. Slide a and b to
reshape the interval, and c, d to move the
shaded region.
The straight-line CDF has a tidy formula on the interval — it is just how far along you are, as a
fraction:
F(x) = \frac{x - a}{b - a}, \qquad a \le x \le b
(with F(x) = 0 below a and
F(x) = 1 above b). Its constant slope is the
density \tfrac{1}{b-a} — a flat density and a straight-line CDF are two
views of the same evenness.
- Density is constant: f(x) = \dfrac{1}{b - a} on [a, b], and 0 outside.
- Probability is a proportion of length: P(c \le X \le d) = \dfrac{d - c}{b - a}.
- The CDF is a straight line: F(x) = \dfrac{x - a}{b - a} on [a, b].
- Mean is the midpoint: \mu = \dfrac{a + b}{2}.
- Variance is \sigma^2 = \dfrac{(b - a)^2}{12}.
Centre and spread
Where is the "average" of a flat distribution? By symmetry it can only be the
midpoint. Balance the rectangle on a fingertip and it tips exactly halfway along:
\mu = \frac{a + b}{2}.
The spread is measured by the
variance, and for the uniform it has a famous, clean form:
\sigma^2 = \frac{(b - a)^2}{12}.
Notice it depends only on the width (b - a), not on where the
interval sits: sliding the whole rectangle left or right changes the mean but never the spread. The
mysterious 12 is not a fudge — it drops straight out of integrating
x^2 across the interval, and it makes the standard deviation about
0.29 of the interval's width.
Worked example 1 — a random number on [0, 10]
Let X \sim U(0, 10). The interval has width
b - a = 10, so the density is a flat
f(x) = \tfrac{1}{10} = 0.1 across the whole stretch.
A probability. What is P(3 \le X \le 7)? The sub-interval
[3, 7] has length 4, so we take the fraction of
the whole:
P(3 \le X \le 7) = \frac{7 - 3}{10 - 0} = \frac{4}{10} = 0.4.
No integral needed — the middle 40% of the interval carries 40% of the probability.
The mean. The midpoint of [0, 10] is
\mu = \tfrac{0 + 10}{2} = 5.
The variance. Using \sigma^2 = \tfrac{(b-a)^2}{12},
\sigma^2 = \frac{(10 - 0)^2}{12} = \frac{100}{12} \approx 8.33,
so the standard deviation is \sigma = \sqrt{8.33} \approx 2.89 — right at
that "0.29 \times the width" we predicted.
Worked example 2 — waiting for a bus
Buses on your route are so frequent that, from the moment you arrive at the stop, the next one is
equally likely to come at any instant in the next 15 minutes. Let
W be your waiting time, so W \sim U(0, 15).
What is the chance you wait less than 5 minutes?
The lucky outcomes are the sub-interval [0, 5], of length
5, out of a total window of length 15. So it is
simply the proportion:
P(W < 5) = \frac{5 - 0}{15 - 0} = \frac{5}{15} = \frac{1}{3}.
A one-in-three chance of a short wait — and by the same reasoning your expected wait is the
midpoint, \tfrac{0 + 15}{2} = 7.5 minutes. Notice we wrote
W < 5 with a strict "<", but
W \le 5 would give the identical answer — see the Watch out! below for
why.
Two traps catch people the moment they meet continuous distributions, and the uniform makes both
crystal clear.
1. The height f(x) is not a probability. Take
U(0, 0.5). Its density is
f(x) = \tfrac{1}{0.5} = 2 — a "probability" of 2 would be nonsense!
Densities are perfectly allowed to exceed 1 when the interval is narrower
than one unit. That is fine, because f(x) is a rate, not a
chance. Probability is the area under it, and the area here is still
2 \times 0.5 = 1, exactly as it must be.
2. Any single exact value has probability zero.
P(X = 3) for a continuous variable is
0 — a single point is a rectangle of zero width, so zero area. This sounds
alarming ("then nothing can happen?") but it just means all the probability lives in ranges,
not points. A neat consequence: for a continuous variable,
\le and < give the same
answer, because the endpoints contribute nothing. P(3 \le X \le 7)
and P(3 < X < 7) are equal. (For a discrete variable that is
emphatically not true — there the endpoints carry real chunks of probability.)
Every time a program shuffles a playlist, deals a virtual card, or runs a simulation, it starts from
one primitive: a stream of numbers uniform on [0, 1). Modern generators
(like the Mersenne Twister) churn out bits that pass stringent tests for looking evenly spread and
unpredictable, then scale them into that unit interval. Want a uniform number on
[a, b] instead? Stretch and shift: a + (b - a)\,U.
The truly beautiful part is that this one flat distribution seeds all the others. There is
a trick — the "inverse-CDF" method — where you take a uniform number, feed it backwards through
another distribution's cumulative curve, and out pops a sample from that distribution. Because the
uniform CDF is the plain straight line F(x) = x on
[0,1], it is the perfect neutral raw material. The humble rectangle is,
quietly, the engine room of all computer randomness — and the doorway to the
exponential
distribution of waiting times.