Uniform distribution
Uniform distribution: every value in an interval equally likely. With the default parameters (lower end a = 0, upper end b = 5) its mean is 2.5 and its standard deviation 1.4434. Use the simulator below to draw samples and see it take shape.
Simulate it
Change the parameters, then draw random samples. The bars are the samples; the line is the exact density. With more samples the bars settle onto it.
Samples to draw
What is the uniform distribution?
The continuous uniform distribution spreads probability evenly over an interval from a to b: any two stretches of the same length are equally likely. If a bus comes every 10 minutes and you arrive at a random moment, your wait is uniform between 0 and 10 minutes.
It is the starting point of simulation: random number generators produce uniform numbers on [0, 1], and every other distribution can be built from them. In Bayesian statistics it is the 'no preference' prior for an unknown probability.
Where it is used
- Waiting time for a service that runs on a fixed schedule when you arrive at random.
- Rounding error when measuring to the nearest unit (uniform on −0.5 to 0.5).
- Random numbers in a simulation.
- A flat prior for a probability between 0 and 1.
Shape and parameters
The density is a flat rectangle of height 1/(b − a). The mean is the midpoint and the standard deviation is the width divided by √12, about 0.29 of the width.
What it assumes
- Known lower and upper limits.
- No part of the interval is more likely than another.
How it relates to other distributions
- Discrete uniform distribution: The version for whole numbers.
- Beta distribution: Beta(1, 1) is the uniform distribution on [0, 1].
Common mistakes
- Assuming 'I know nothing' means uniform when the scale matters (uniform on a number is not uniform on its logarithm).
- Using it when the range is not really bounded.
How to work it out
- 1
The probability density function (the formula that gives the shape):
- 2
Its mean (the long-run average) and variance (the spread):
- 3
Worked example with the default parameters (lower end a = 0, upper end b = 5): For a uniform distribution from 0 to 5, what is the probability of a value between 1 and 3.5?
LaTeX source of the formulas on this page
\[ f(x)=\frac{1}{b-a},\quad a\le x\le b \]
\[ \mu = \frac{a+b}{2},\qquad \sigma^2 = \frac{(b-a)^2}{12} \]
\[ \text{answer} = 0.5000 \]At a glance
| Property | Value |
|---|---|
| Type | Continuous (measurements) |
| Parameters | lower end a; upper end b |
| Possible values | a to b |
| Mean | 2.5 |
| Variance | 2.0833 |
| Standard deviation | 1.4434 |
| Example (lower end a = 0, upper end b = 5) | For a uniform distribution from 0 to 5, what is the probability of a value between 1 and 3.5? Answer: 0.5000. |
How to compute it in Excel, Python and R
| Tool | Function |
|---|---|
| Excel / Google Sheets | =1/(b-a) for a ≤ x ≤ b; =RAND()*(b-a)+a to simulate |
| Python (SciPy) | scipy.stats.uniform.pdf(x, loc=a, scale=b - a) |
| R | dunif(x, a, b) |
Questions
What is the uniform distribution used for?
Every value in an interval equally likely. Typical uses: Waiting time for a service that runs on a fixed schedule when you arrive at random. Rounding error when measuring to the nearest unit (uniform on −0.5 to 0.5). Random numbers in a simulation.
What are the mean and variance of the uniform distribution?
Mean: μ = (a+b)/(2). Variance: σ² = ((b-a)²)/(12).
What does the uniform distribution assume?
Known lower and upper limits. No part of the interval is more likely than another.
How do I calculate it in Excel?
=1/(b-a) for a ≤ x ≤ b; =RAND()*(b-a)+a to simulate
How is the uniform distribution related to other distributions?
Discrete uniform distribution: The version for whole numbers. Beta distribution: Beta(1, 1) is the uniform distribution on [0, 1].