Search

Search papers and lessons

Uniform Distribution

Level 2 · 10 min read

The uniform distribution spreads probability evenly over an interval, so every value in the interval is equally likely and nothing outside it can occur.

On this page

  • Colour = topic mix
  • Calculus
  • Probability
  • Discrete math
  • Sign in to see your progress

TL;DR

The uniform distribution is the model of "every value in this range is equally likely." Its density is flat: the same height everywhere between two endpoints aa and bb, and zero outside them. The height is 1/(b−a)1/(b-a), so the area under the flat line is exactly one.

It is the simplest continuous distribution, and it is the starting point for almost every other one, because computers generate uniform random numbers and every other distribution is built from them.

Where you'll see it: in random number generators, in the random starting weights and noise used in simulations, and in the sampling steps of Monte Carlo methods and rejection sampling.

Intuition

Equal chances across a range

Picture a spinner with a pointer that stops at a random angle. Every angle is equally likely to be where it stops, so no part of the dial is favoured. Now stretch the dial into a straight line segment. Each piece of the segment, if it is the same width, has the same chance of containing the result. That is the uniform distribution.

A real example is a bus that arrives at a random moment in a ten-minute window, when you know nothing about the timetable except that it comes once every ten minutes and you turned up at a random point in that cycle. Your waiting time is uniform between zero and ten minutes.

When should you reach for it? When you know a quantity lies between two limits and you have no good reason to prefer any part of that range over another. Pierre-Simon Laplace argued around the turn of the 19th century that this kind of ignorance should be modelled by equal chances. That argument is the "principle of indifference," and the uniform distribution is its formal version.

The density is a flat line over the interval, and the probability of any sub-interval is simply the fraction of the whole that it covers.

−0.500.511.522.500.20.40.60.8xdensity f(x)
  • uniform on [0, 2]
The density is flat on [0, 2] and zero outside. The total area is the width 2 times the height 0.5, which is 1.

Only the endpoints matter

Within the interval, nothing distinguishes one point from another. The density does not peak in the middle, lean to one side, or taper at the edges. Two numbers, the endpoints, describe the whole model. That makes it a useful baseline: anything more elaborate has to justify the extra structure it adds.

The math

Definition

Definition: Uniform distribution

A continuous random variable XX is uniform on the interval from aa to bb, written X∼U(a,b)X \sim \mathcal{U}(a, b), when its density is

f(x)={1b−aa≤x≤b0otherwise,f(x) = \begin{cases} \dfrac{1}{b-a} & a \le x \le b \\ 0 & \text{otherwise,} \end{cases}

where a<ba \lt b are the two endpoints.

The symbol b−ab-a is the width of the interval. The density is the reciprocal of that width. Check that it is a valid density: it is never negative, and the area is the width times the height,

∫−∞∞f(x) dx=∫ab1b−a dx=1b−a (b−a)=1.\int_{-\infty}^{\infty} f(x)\,dx = \int_a^b \frac{1}{b-a}\,dx = \frac{1}{b-a}\,(b-a) = 1.

The integral is a definite integral of a constant, which is just the constant times the width.

Probabilities are fractions of the width

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

P(c≤X≤d)=∫cd1b−a dx=d−cb−a.P(c \le X \le d) = \int_c^d \frac{1}{b-a}\,dx = \frac{d-c}{b-a}.

The probability is the length of the sub-interval divided by the length of the whole interval. Nothing else enters. This is the whole meaning of "equally likely" for a continuous variable.

The cumulative distribution function

The CDF is the running total of probability. Integrate the density from the far left up to xx:

F(x)={0x<ax−ab−aa≤x≤b1x>b.F(x) = \begin{cases} 0 & x \lt a \\[4pt] \dfrac{x-a}{b-a} & a \le x \le b \\[4pt] 1 & x \gt b. \end{cases}

Below aa there is no probability yet, so FF is zero. Above bb all probability has been counted, so FF is one. In between, FF rises in a straight line from 0 to 1. Its slope is 1/(b−a)1/(b-a), which is the density, as the fundamental theorem of calculus requires.

Mean and variance

The mean is the expected value of XX:

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

Factor the top as (b−a)(b+a)(b-a)(b+a) and the (b−a)(b-a) cancels:

E[X]=a+b2.\mathbb{E}[X] = \frac{a+b}{2}.

The mean is the midpoint, as symmetry suggests.

For the variance, first compute the second moment:

E[X2]=∫abx2b−a dx=b3−a33(b−a)=a2+ab+b23.\mathbb{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}.

Then subtract the square of the mean:

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

The standard deviation is therefore

σ=b−a12≈0.289 (b−a).\sigma = \frac{b-a}{\sqrt{12}} \approx 0.289\,(b-a).

The spread is always about 29 percent of the width. A uniform distribution on a wide interval is wide, but it is never as spread out as its endpoints might suggest.

Generating uniform samples

A computer's random number generator gives samples that approximate U∼U(0,1)U \sim \mathcal{U}(0, 1). Any other uniform variable can be built from one:

X=a+(b−a) U⟹X∼U(a,b).X = a + (b-a)\,U \quad\Longrightarrow\quad X \sim \mathcal{U}(a, b).

Check this with the CDF. The event X≤xX \le x is the same as U≤(x−a)/(b−a)U \le (x-a)/(b-a), so

P(X≤x)=P ⁣(U≤x−ab−a)=x−ab−a.P(X \le x) = P\!\left(U \le \frac{x-a}{b-a}\right) = \frac{x-a}{b-a}.

That is the CDF of U(a,b)\mathcal{U}(a, b), so the transformed variable has the right distribution. The same idea, applying the inverse of a CDF to a uniform draw, is the inverse transform method, which uses the CDF to generate samples from almost any distribution.

Worked examples

Example
A uniform on [0, 2]

Let X∼U(0,2)X \sim \mathcal{U}(0, 2). The width is b−a=2b-a = 2, so the density is f(x)=1/2f(x) = 1/2 on [0,2][0, 2] and zero elsewhere.

  1. Probability of landing between 0.5 and 1.5: P(0.5≤X≤1.5)=1.5−0.52=12=0.5P(0.5 \le X \le 1.5) = \dfrac{1.5 - 0.5}{2} = \dfrac{1}{2} = 0.5.
  2. The same answer from the CDF: F(1.5)=1.52=0.75F(1.5) = \dfrac{1.5}{2} = 0.75 and F(0.5)=0.52=0.25F(0.5) = \dfrac{0.5}{2} = 0.25, so F(1.5)−F(0.5)=0.5F(1.5) - F(0.5) = 0.5.
  3. The mean is 0+22=1\dfrac{0 + 2}{2} = 1.
  4. The variance is (2−0)212=412=13\dfrac{(2-0)^2}{12} = \dfrac{4}{12} = \dfrac{1}{3}, so the standard deviation is about 0.5770.577.

Interpretation: the middle half of the interval, from 0.5 to 1.5, holds exactly half of the probability. That is what "uniform" means. Each unit of width carries the same share, so the middle half of the width carries half the mass.

Example
A bus at a random moment

A bus comes every 10 minutes, and you arrive at the stop at a random time. Your wait XX is uniform on [0,10][0, 10] minutes, so f(x)=1/10f(x) = 1/10 there.

  1. Chance the wait is longer than 7 minutes: P(X>7)=10−710=0.3P(X \gt 7) = \dfrac{10-7}{10} = 0.3.
  2. Chance the wait is at most 4 minutes: P(X≤4)=4−010=0.4P(X \le 4) = \dfrac{4-0}{10} = 0.4.
  3. Chance the wait is longer than 7 minutes, given you have already waited more than 4: P(X>7∣X>4)=P(X>7)P(X>4)=0.30.6=0.5P(X \gt 7 \mid X \gt 4) = \dfrac{P(X \gt 7)}{P(X \gt 4)} = \dfrac{0.3}{0.6} = 0.5.
  4. Expected wait: E[X]=0+102=5\mathbb{E}[X] = \dfrac{0+10}{2} = 5 minutes.
  5. Standard deviation of the wait: 1012≈2.89\dfrac{10}{\sqrt{12}} \approx 2.89 minutes.

Interpretation: step 3 shows that the uniform is not memoryless. Having already waited 4 minutes, you know XX lies in [4,10][4, 10], and given that it is still uniform, now over a window of 6 minutes. The chance of waiting more than 3 further minutes is 3/6=0.53/6 = 0.5, whereas at the start it was 0.70.7. Waiting makes the bus more likely to arrive soon, because the window is shrinking. The distribution that forgets how long you have waited is the exponential, not the uniform. The uniform fits only when your arrival time is random relative to a fixed ten-minute cycle.

Tradeoffs and failure modes

The uniform model is only as good as its endpoints. Choosing aa and bb is the entire modelling decision, and a wrong choice cannot be fixed by anything else in the model.

SituationWhat goes wrong with a uniformBetter choice
Error is the sum of many small independent causesThe uniform has hard edges and too little mass in the middle; real errors are bell-shaped[[gaussian-distribution
The true value might sometimes fall outside your rangeThe model assigns zero probability to values that do happenA wider range, or a distribution with unbounded support
You need samples from a distribution with a known CDFThe uniform does not produce that shape by itselfInverse transform, or [[rejection-sampling
The outcome is one of a finite set (a die face, a card)A continuous uniform is the wrong type of variableThe discrete uniform on the finite set
You want a "non-informative" prior on a parameterA uniform on xx is not uniform on log⁡x\log x, so the prior depends on how you parametriseThink about scale first, and choose a prior that is uniform on the natural scale

The last row is a real trap. "Equal chances" depends on the variable you choose to be uniform. A uniform on the number xx puts a different belief on log⁡x\log x than a uniform on log⁡x\log x does. Pick the scale that matches what you actually know.

History

The idea of splitting belief equally over possibilities you cannot tell apart is much older than the formal distribution. Pierre-Simon Laplace used it as the principle of insufficient reason, later called the principle of indifference. The continuous uniform became a standard model as probability theory came to be expressed through densities and integrals.

Its largest practical role came with computers. In the mid-20th century, researchers needed streams of random numbers for simulations, and the standard approach was to build generators whose outputs look uniform on [0,1)[0, 1). Every other random variable in a simulation is then produced by transforming those uniform numbers. The uniform is therefore the foundation of sampling, not just one distribution among many.

Check yourself

QuestionRecall: what is the density of a uniform distribution on [a, b], and why must it have that height?Show answer

The density is f(x)=1/(b−a)f(x) = 1/(b-a) on [a,b][a, b] and zero elsewhere. The height must be 1/(b−a)1/(b-a) because the total area under the density must be 1. The base of the rectangle is the width b−ab-a, so the height has to be the reciprocal of that width.

QuestionComputation: if X is uniform on [2, 6], what is P(X ≤ 3.5)?Show answer

The width is 6−2=46 - 2 = 4. The probability of being at most 3.5 is the length of [2,3.5][2, 3.5] divided by the width: (3.5−2)/4=1.5/4=0.375(3.5 - 2)/4 = 1.5/4 = 0.375. Equivalently, F(3.5)=(3.5−2)/(6−2)=0.375F(3.5) = (3.5 - 2)/(6 - 2) = 0.375.

QuestionWhy: a bus wait is uniform on [0, 10] minutes and you have already waited 4. What is the distribution of the remaining wait, and is it the same as at the start?Show answer

Conditioning on X>4X \gt 4 restricts the variable to [4,10][4, 10], and the density there is still flat. The remaining wait is therefore uniform on [0,6][0, 6] minutes, with mean 3, not the original uniform on [0,10][0, 10] with mean 5. So it is not the same: the uniform is not memoryless, and the bus gets more likely to arrive soon as the window shrinks.

QuestionApplied: a sensor's rounding error is uniform between minus 0.5 and plus 0.5 degrees. A colleague wants to model it as Gaussian noise with standard deviation 0.5. Is that a good match?Show answer

The uniform error has standard deviation (0.5−(−0.5))/12=1/12≈0.289(0.5 - (-0.5))/\sqrt{12} = 1/\sqrt{12} \approx 0.289, which is smaller than 0.5. A Gaussian with standard deviation 0.5 would put real probability outside ±0.5\pm 0.5, which the sensor can never produce, and it would have a bell shape instead of a flat one. It overstates the spread and the tails. Use the uniform with its exact bounds if you know the error is bounded, and check the mean and variance against the uniform formulas before swapping models.

Sources