Understanding the uniform distribution calculator — concept and principle
A uniform distribution calculator handles the case where every value between a minimum a and a maximum b is equally likely. It returns the probability that the variable falls in a chosen sub-interval, along with the mean and variance. Typical examples are a random number from a generator, the arrival time of a bus within a known 10-minute window, rounding errors, and the position of a randomly placed point on a line.
How it is calculated
- P(from < X < to) = (min(to, b) − max(from, a)) ÷ (b − a). The interval you ask about is clipped to the range [a, b].
- Mean = (a + b) ÷ 2, the midpoint of the range.
- Variance = (b − a)² ÷ 12; the standard deviation is (b − a) ÷ √12 ≈ 0.2887 × (b − a).
The density is constant, f(x) = 1 ÷ (b − a) for a ≤ x ≤ b and zero elsewhere. All values share one unit, and b must be greater than a. Because the variable is continuous, including or excluding the endpoints does not change the probability.
The principle
"Equally likely" means the probability is spread evenly, like butter of the same thickness over a slice of bread. The total area under the density must equal 1, so its height is 1 ÷ (b − a). The probability of any sub-interval is then just its length times that height, which is the length of the sub-interval divided by the length of the whole range. The mean sits at the centre by symmetry, and the variance follows from integrating (x − mean)² × f(x) over the range, giving (b − a)²/12.
Worked example
- Inputs: a = 0, b = 10, from = 2, to = 5.
- Clipped interval: max(2, 0) = 2 to min(5, 10) = 5, length 3.
- P(2 < X < 5) = 3 ÷ (10 − 0) = 0.3.
- Mean = (0 + 10) ÷ 2 = 5.
- Variance = (10 − 0)² ÷ 12 = 100 ÷ 12 ≈ 8.3333; SD ≈ 2.887.
| Max b | P(from < X < to) |
|---|---|
| 2.5 | 0.2 |
| 5 | 0.6 |
| 7.5 | 0.4 |
| 10 | 0.3 |
| 12.5 | 0.24 |
| 15 | 0.2 |
| 20 | 0.15 |
How to read the result
The probability is simply the fraction of the range you cover: 30% of the range gives a 30% chance. Unlike the normal distribution, there is no clustering near the mean; values near the edges are just as likely as values in the middle.
Common mistakes
- Using a uniform model for things that clearly cluster, such as heights or test scores.
- Entering an interval that lies entirely outside [a, b]; the true probability is then 0, so check that the interval overlaps the range.
- Confusing the continuous uniform with a discrete one such as a fair die, where the variance is (n² − 1) ÷ 12.
Frequently asked questions
What is the probability of one exact value?
Zero, because a single point has no length.
How do I generate a uniform number between a and b?
Take a standard random number U between 0 and 1 and compute a + (b − a) × U.
Why divide by 12 in the variance?
It comes from integrating the squared distance from the midpoint over the range; for a range of length L the result is L²/12.
Sources: Ross, S. M., A First Course in Probability (Pearson) · NIST/SEMATECH e-Handbook of Statistical Methods, Section 1.3.6.6.2 Uniform Distribution