Uniform Distribution

The distribution that spreads probability evenly, either over an interval or over a finite set of equally likely values.

Prerequisites: Probability Distributions, Expected Value, Variance of a Random Variable.

The uniform distribution spreads probability evenly. In its continuous form, every stretch of the same length inside an interval from aa to bb is equally likely to contain the value, and values outside the interval are impossible. In its discrete form, each of a finite set of values, such as the six faces of a fair die, has the same probability.

It is the simplest model of “no value is favoured over any other” and is mostly useful for that reason: as a model of complete uncertainty within known limits, as a building block in probability arguments, and as the starting point of almost every computer simulation, since random number generators produce (approximately) uniform numbers between 00 and 11.

Intuition

Suppose a bus comes every 20 minutes and you arrive at the stop at a random moment, without checking the timetable. Your waiting time could be anything from 00 to 2020 minutes, and there is no reason for any part of that range to be more likely than another. The chance of waiting between 0 and 5 minutes is the same as the chance of waiting between 15 and 20 minutes: each stretch is a quarter of the window, so each has probability 0.250.25.

That is the continuous uniform distribution: probability is proportional to length. Its density is flat, like a rectangle, and the height of the rectangle is whatever makes its area equal to 11.

Left: two flat, rectangular densities. The one on the interval from 0 to 1 has height 1; the wider one from 2 to 6 has height 0.25, so both rectangles have area 1. Right: the corresponding CDFs are 0 to the left of the interval, rise in a straight line across it, and stay at 1 to the right.
Continuous uniform distributions on [0, 1] (solid) and [2, 6] (dashed). Left: densities; a wider interval gives a lower rectangle. Dotted lines mark the jumps at the ends of each interval. Right: the CDF rises linearly from 0 at a to 1 at b.

Definition

A continuous random variable XX has a uniform distribution on the interval from aa to bb, written X∼Uniform(a,b)X \sim \text{Uniform}(a, b), if its probability density function is

f(x)={1b−aif a≤x≤b,0otherwise.f(x) = \begin{cases} \dfrac{1}{b - a} & \text{if } a \le x \le b, \\[1ex] 0 & \text{otherwise.} \end{cases}

The two parameters are the endpoints aa and bb, any real numbers with a<ba < b. The height 1/(b−a)1/(b-a) is fixed by the requirement that the total area is 11: a rectangle of width b−ab - a and height 1/(b−a)1/(b-a) has area exactly 11. The special case Uniform(0,1)\text{Uniform}(0, 1) is called the standard uniform distribution.

Whether the endpoints are included makes no difference, because a single point has probability 00 for a continuous variable.

Probabilities are lengths

For any interval [c,d][c, d] inside [a,b][a, b],

P(c≤X≤d)=d−cb−a,P(c \le X \le d) = \frac{d - c}{b - a},

the length of the interval divided by the length of the whole range. The cumulative distribution function is

F(x)=P(X≤x)={0if x<a,x−ab−aif a≤x≤b,1if x>b,F(x) = P(X \le x) = \begin{cases} 0 & \text{if } x < a, \\[0.5ex] \dfrac{x - a}{b - a} & \text{if } a \le x \le b, \\[1ex] 1 & \text{if } x > b, \end{cases}

a straight ramp from 00 to 11 across the interval, as in the right panel of the figure.

Mean and variance

If X∼Uniform(a,b)X \sim \text{Uniform}(a, b), then

E⁡[X]=a+b2,Var⁡(X)=(b−a)212.\E[X] = \frac{a + b}{2}, \qquad \Var(X) = \frac{(b - a)^2}{12}.

The mean is the midpoint of the interval, as symmetry suggests. It also follows from the integral:

E⁡[X]=∫abxb−a dx=b2−a22(b−a)=a+b2,\E[X] = \int_a^b \frac{x}{b - a}\, dx = \frac{b^2 - a^2}{2(b - a)} = \frac{a + b}{2},

using b2−a2=(b−a)(b+a)b^2 - a^2 = (b - a)(b + a). For the variance, first compute

E⁡[X2]=∫abx2b−a dx=b3−a33(b−a)=a2+ab+b23,\E[X^2] = \int_a^b \frac{x^2}{b - a}\, dx = \frac{b^3 - a^3}{3(b - a)} = \frac{a^2 + ab + b^2}{3},

using b3−a3=(b−a)(a2+ab+b2)b^3 - a^3 = (b - a)(a^2 + ab + b^2). Then

Var⁡(X)=E⁡[X2]−(E⁡[X])2=a2+ab+b23−(a+b)24=(b−a)212.\Var(X) = \E[X^2] - (\E[X])^2 = \frac{a^2 + ab + b^2}{3} - \frac{(a + b)^2}{4} = \frac{(b - a)^2}{12}.

(Put both fractions over 1212: the numerator is 4a2+4ab+4b2−3a2−6ab−3b2=(b−a)24a^2 + 4ab + 4b^2 - 3a^2 - 6ab - 3b^2 = (b - a)^2.)

So the variance depends only on the width of the interval, not on where it sits, and the standard deviation is (b−a)/12≈0.29 (b−a)(b - a)/\sqrt{12} \approx 0.29\,(b - a). For the standard uniform, Var⁡(X)=1/12≈0.083\Var(X) = 1/12 \approx 0.083.

How the shape depends on a and b

There is only one shape, a rectangle; the parameters move and stretch it.

Worked example

A bus arrives every 20 minutes and you turn up at a random time, so your waiting time WW in minutes is Uniform(0,20)\text{Uniform}(0, 20), with density 1/201/20 on that interval.

Step 1: average wait. E⁡[W]=(0+20)/2=10\E[W] = (0 + 20)/2 = 10 minutes.

Step 2: a long wait. The probability of waiting more than 15 minutes is the length from 15 to 20 divided by 20:

P(W>15)=20−1520=0.25.P(W > 15) = \frac{20 - 15}{20} = 0.25.

Step 3: a range. The probability of waiting between 5 and 8 minutes is (8−5)/20=0.15(8 - 5)/20 = 0.15.

Step 4: spread. Var⁡(W)=202/12≈33.3\Var(W) = 20^2 / 12 \approx 33.3 square minutes, so the standard deviation is 20/12≈5.820/\sqrt{12} \approx 5.8 minutes. A typical wait is about 6 minutes away from the 10-minute average, which fits a range that runs evenly from 0 to 20.

The discrete uniform distribution

A discrete uniform distribution puts equal probability on each of a finite set of values. The roll of a fair six-sided die is the standard example: P(X=k)=1/6P(X = k) = 1/6 for k=1,2,…,6k = 1, 2, \dots, 6.

It differs from the continuous version in the usual way that discrete and continuous distributions differ: each possible value has a positive probability, 1/61/6, rather than a density, and probabilities of sets are sums rather than areas. The mean is again the midpoint, (1+6)/2=3.5(1 + 6)/2 = 3.5, but the variance is not (b−a)2/12(b - a)^2/12. For the die,

Var⁡(X)=E⁡[X2]−(E⁡[X])2=1+4+9+16+25+366−3.52=916−12.25=3512≈2.92,\Var(X) = \E[X^2] - (\E[X])^2 = \frac{1 + 4 + 9 + 16 + 25 + 36}{6} - 3.5^2 = \frac{91}{6} - 12.25 = \frac{35}{12} \approx 2.92,

whereas the continuous formula with a=1a = 1 and b=6b = 6 would give 25/12≈2.0825/12 \approx 2.08.

Uniform numbers in simulation

Computers generate pseudo-random numbers that behave like independent draws from Uniform(0,1)\text{Uniform}(0, 1). Almost every other random quantity in a simulation is built from these.

Common misunderstandings

“Uniform means every exact value has the same probability.” For the continuous uniform, every exact value has probability 00. What is equal is the probability of intervals of equal length.

“Random means uniform.” Random only means uncertain. Most random quantities are not uniform: heights cluster around a typical value, waiting times between random events are more often short than long. Choosing a uniform distribution is a modelling assumption that needs a reason, such as the bus timetable above.

“A uniform prior means knowing nothing.” A uniform distribution on a quantity is not uniform on transformations of it. If a length is uniform between 1 and 2, its square is not uniform between 1 and 4. “Flat” depends on the scale you choose.

“The density must be at most 1.” A density is not a probability. A uniform distribution on a short interval has a density greater than 11.

Further reading