Uniform Distribution Calculator
Find continuous uniform probabilities below, above, between or outside values, or the x that matches a given probability. Enter the minimum and maximum; the mean, variance and median come with a shaded chart of the flat density.
The smallest possible value
The largest possible value; must be greater than the minimum
Related Calculators
Random Number Generator
Generate cryptographically secure random integers or decimals in any range, with or without repeats.
Beta Distribution Calculator
Beta distribution probabilities and quantiles for a proportion from α and β, with mean, variance, mode, skewness and a shaded density chart.
Normal Distribution Calculator
Work with the normal curve, cumulative probabilities, and related z-score outputs.
What the continuous uniform distribution describes
Every value between the minimum and the maximum is equally likely, so the density is a flat rectangle of height 1/(max − min) and a probability is simply a length: the chance of landing in an interval is the part of the interval that lies inside the range divided by the full range. Textbooks write the distribution as U(a, b); this page calls the ends min and max so they are not confused with the limits a and b of the interval whose probability you ask for.
f(x) = 1 / (max − min) for min ≤ x ≤ max, and 0 elsewhere
F(x) = (x − min) / (max − min) for min ≤ x ≤ max (0 below the range, 1 above it)
P(a ≤ X ≤ b) = (b − a) / (max − min) for an interval inside the range
Mean = median = (min + max) / 2 Variance = (max − min)² / 12 Skewness = 0
Inverse: x = min + p (max − min)
Where it is used
- A waiting time when something happens at an unknown moment inside a known window, such as a delivery promised between 2 and 10 minutes from now.
- Rounding error: rounding to the nearest whole number gives an error uniform on −0.5 to 0.5.
- Random numbers: the RAND function of a spreadsheet and the random number generator draw uniformly from a range, and draws from other distributions are built from uniform ones.
- P-values: when the null hypothesis is true and the test statistic is continuous, the p-value is uniform on 0 to 1, which is why a level-α test rejects a true null hypothesis with probability α.
Worked example
A delivery is due at some moment between minute 2 and minute 10, all moments equally likely. The probability that it arrives between minute 3 and minute 6 is (6 − 3)/(10 − 2) = 3/8 = 0.375, so the probability of arriving outside that interval is 0.625. The mean and median are (2 + 10)/2 = 6, the variance is 8²/12 = 5.3333 and the standard deviation is 2.3094 minutes. The 90th percentile is 2 + 0.9 × 8 = 9.2. Load example fills in these values.
Software equivalents
| Software | Cumulative probability | Inverse | Random draw |
|---|---|---|---|
| Excel / Sheets | =MAX(0, MIN(1, (x-min)/(max-min))) | =min+p*(max-min) | =min+(max-min)*RAND() |
| R | punif(x, min, max) | qunif(p, min, max) | runif(n, min, max) |
| Python (SciPy) | scipy.stats.uniform.cdf(x, loc=min, scale=max-min) | scipy.stats.uniform.ppf(p, loc=min, scale=max-min) | numpy.random.uniform(min, max) |
| MATLAB | unifcdf(x, a, b) | unifinv(p, a, b) | unifrnd(a, b) |
Spreadsheets have no uniform CDF function, so the formula above clips the ratio to the range from 0 to 1. For related continuous models see the beta distribution, which generalises the uniform (Beta(1, 1) is uniform on 0 to 1), and the normal distribution.
Frequently Asked Questions
How do I find the probability that a uniform variable lies between two values?
Divide the length of the part of your interval that lies inside the range by the full length: P(a ≤ X ≤ b) = (b − a)/(max − min). If the interval sticks out of the range, cut it back to the range first; the part outside has probability zero.
What are the mean and variance of a uniform distribution?
The mean and median are both (min + max)/2 and the variance is (max − min)²/12. For the uniform distribution on 0 to 1 that gives a mean of 0.5 and a variance of 1/12 = 0.0833.
What is the difference between the continuous and the discrete uniform distribution?
The discrete version puts the same probability 1/n on each of n separate values, such as the faces of a fair die, and has variance (n² − 1)/12. This calculator is the continuous version, where every real number in the range is possible and single values have probability zero.
Why does the uniform distribution have no single mode?
Every value in the range has the same density, so each one is as likely as any other. The calculator therefore reports the whole range as the mode.
How do I generate a uniform random number between two values?
In Excel or Google Sheets use =min+(max-min)*RAND(), with your own numbers in place of min and max. In R use runif(1, min, max), and in Python use numpy.random.uniform(min, max) or random.uniform(min, max).
What is the probability of a value below the minimum or above the maximum?
Below the minimum the cumulative probability is 0 and above the maximum it is 1, because the density is zero outside the range. The calculator accepts x values outside the range and returns those limits.
Embed This Calculator
Add this free calculator to your course page or LMS.
Adjust the height value to fit your page.