Uniform

X∼U(a,b)X \sim \mathcal{U}(a, b)

A continuous value equally likely to fall anywhere between a and b, so its density is a flat rectangle of height 1/(b − a).

The story

Pick a point at random on a ruler between aa and bb, with no preference for any part. The chance of landing in any sub-interval depends only on its length: P(c≤X≤d)=(d−c)/(b−a)P(c \le X \le d) = (d - c)/(b - a). The CDF is therefore a straight ramp rising from 0 at aa to 1 at bb.

Its mean is the midpoint (a+b)/2(a + b)/2 and its variance is (b−a)2/12(b - a)^2/12. The Uniform(0, 1) is also the raw material of simulation: computers generate uniform random numbers and transform them into everything else, for instance by feeding them through an inverse CDF.

Formulas

Support

x∈[a,b]x \in [a, b]

PDF

f(x)=1b−af(x) = \frac{1}{b - a}

CDF

F(x)=x−ab−aF(x) = \frac{x - a}{b - a}

Expectation

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

Variance

Var⁡(X)=(b−a)212\operatorname{Var}(X) = \frac{(b - a)^2}{12}

Parameters

ParameterWhat it controls
aaThe lower end of the interval. Keep it below bb.
bbThe upper end of the interval. Wider intervals give a lower, flatter rectangle, since the total area must stay 1.

Where it shows up

  • The output of a random number generator such as Math.random(), on [0,1)[0, 1).
  • The rounding error when a measurement is rounded to the nearest unit, roughly uniform on [−0.5,0.5][-0.5, 0.5].
  • The arrival time of a bus that comes once every ten minutes, if you turn up at a random moment.
  • The angle at which a spun bottle comes to rest, uniform on [0∘,360∘)[0^\circ, 360^\circ).

Try this

  1. Set a=0a = 0 and b=1b = 1, then toggle to the CDF view: it is a straight line, so P(X≤x)P(X \le x) is simply xx. Shade from 0.2 to 0.5 and confirm the probability is 0.3.
  2. With a=0a = 0 and b=1b = 1, switch to Sample means with n=2n = 2. The averages form a triangle, not a rectangle. Try n=3n = 3 and then n=12n = 12 and watch the Central Limit Theorem take over.
  3. Press Draw 1000 on Uniform(0, 1) and compare the sample variance with 1/12≈0.08331/12 \approx 0.0833. Then widen bb to 4 and check that the variance grows to 16/12≈1.3316/12 \approx 1.33, because it scales with the square of the width.

Related distributions

  • It is the continuous counterpart of the Discrete Uniform.
  • Uniform(0, 1) is the Beta with α=β=1\alpha = \beta = 1.
  • If UU is Uniform(0, 1), then −ln⁡(U)/λ-\ln(U)/\lambda is Exponential with rate λ\lambda; this is the inverse-CDF trick in action.
  • The mean of nn independent Uniforms tends to a Normal as nn grows; even n=12n = 12 already looks convincingly bell-shaped.