Uniform Distribution Calculator
Enter the lower bound (a), the upper bound (b), and an optional x value to compute the probability density, cumulative probability, complementary probability, and all key statistical measures for a continuous uniform distribution. You can also find the probability that X falls between any two values c and d. Results update as you type.
Formula
Worked example
U(2, 8): range = 6, PDF = 1/6 = 0.1667, mean = (2+8)/2 = 5, variance = 36/12 = 3, sigma = sqrt(3) = 1.732. At x = 5: P(X <= 5) = (5-2)/6 = 0.5. P(3 <= X <= 7) = (7-3)/6 = 4/6 = 0.667.
What is a uniform distribution?
A continuous uniform distribution, written U(a, b), assigns equal probability density to every value in the interval from a to b. No point in that interval is more likely than any other. The probability density function is simply 1/(b-a), a flat horizontal line of height equal to the reciprocal of the interval width. Outside [a, b] the density is zero. This rectangular shape is why the distribution is sometimes called the rectangular distribution. Common uses include random number generation, simulation seeding, rounding-error analysis, and any situation where prior knowledge says only that a quantity lies within a certain range but gives no reason to prefer one part of the range over another.
How to calculate probabilities
Because the PDF is constant, every probability is just a length divided by a total length. To find P(X <= x), subtract a from x and divide by b - a: this is the cumulative distribution function F(x) = (x-a)/(b-a). To find the probability that X falls in any sub-interval [c, d] within [a, b], compute (d-c)/(b-a), the width of the sub-interval as a fraction of the total width. To find the complementary probability P(X > x), subtract P(X <= x) from 1. If x falls outside [a, b], the CDF is simply 0 (below a) or 1 (above b). The inverse CDF (quantile function) is Q(p) = a + p*(b-a), which lets you find the value x such that exactly p of the distribution lies below it.
Mean, variance, and other moments
The mean (expected value) is the midpoint of the interval: mu = (a+b)/2. The variance reflects how spread out the distribution is and equals (b-a)^2/12. The standard deviation is (b-a)/sqrt(12), which is roughly 0.2887 times the interval width. Because the distribution is perfectly symmetric around its midpoint, skewness is 0 and the median equals the mean. The excess kurtosis is -6/5 = -1.2, making the distribution platykurtic: its tails are lighter and its top is flatter than a normal distribution with the same variance. The distribution has maximum entropy among all continuous distributions with a fixed, bounded support, which is why it is the default choice when only the bounds are known.
Discrete uniform distribution
When the outcomes are a finite set of equally likely integers, the discrete uniform distribution applies. For n outcomes labelled 1 through n, each has probability 1/n. The mean is (n+1)/2 and the variance is (n^2-1)/12. Rolling a fair six-sided die is a classic example: n=6, each face has probability 1/6, mean = 3.5, variance = 35/12. Drawing a card from a standard deck without looking is another: n = 52 for suit, n = 13 for rank. The continuous calculator above applies to continuous intervals; for integer outcomes use n = b - a + 1 and replace the integral formulas with sums.
Key properties of U(a, b)
| Property | Formula | Notes |
|---|---|---|
| PDF f(x) | 1 / (b - a) | Constant for x in [a, b], zero elsewhere |
| CDF F(x) | (x - a) / (b - a) | Linear from 0 at x = a to 1 at x = b |
| Mean | (a + b) / 2 | Midpoint of the interval |
| Median | (a + b) / 2 | Equals the mean (symmetric distribution) |
| Mode | Any value in [a, b] | Every point is equally likely |
| Variance | (b - a)^2 / 12 | Increases with the square of the interval width |
| Std deviation | (b - a) / sqrt(12) | Approximately 0.2887 * (b - a) |
| Skewness | 0 | Perfectly symmetric around the mean |
| Excess kurtosis | -6/5 = -1.2 | Platykurtic: flatter than a normal distribution |
| Entropy | ln(b - a) | Maximum entropy for a bounded continuous distribution |
Statistical measures for the continuous uniform distribution with parameters a (lower bound) and b (upper bound).
Frequently asked questions
What is the difference between PDF and CDF for a uniform distribution?
The PDF (probability density function) is the height of the distribution curve at any point x. For U(a, b) it is a constant 1/(b-a), so it looks like a flat rectangle between a and b. The CDF (cumulative distribution function) gives the probability that X does not exceed x. It rises linearly from 0 at x = a to 1 at x = b, so its graph is a straight diagonal line over the interval. To find the probability that X lies in any sub-interval, you subtract two CDF values or equivalently divide the sub-interval width by (b-a).
How do I find the probability between two values?
For a continuous uniform distribution U(a, b), the probability that X falls between c and d (where a <= c <= d <= b) is simply (d-c)/(b-a). This is the width of the sub-interval divided by the total width. For example, for U(0, 10) the chance X lies between 3 and 7 is (7-3)/10 = 0.4, or 40%. Use the "Interval lower bound (c)" and "Interval upper bound (d)" inputs in this calculator to compute it directly.
What is the standard uniform distribution?
The standard uniform distribution is U(0, 1) with a = 0 and b = 1. Every value between 0 and 1 is equally likely, the PDF is 1 everywhere in that interval, the mean is 0.5, and the variance is 1/12. Most programming languages and statistical packages generate standard uniform random numbers by default (e.g. Math.random() in JavaScript, random.random() in Python), and then transform them to any other uniform distribution via x = a + (b-a)*u where u is the standard uniform value.
When is a uniform distribution appropriate?
Use a uniform distribution when you know a value lies within a range but have no reason to expect any particular part of the range to be more likely than another. Examples include rounding errors (which are approximately uniform within a half-unit on either side of a round number), manufacturing tolerances when a part must lie within a spec but the process has no tendency toward any specific value, simulation inputs when only bounds are known, and random sampling indexes. If you do have information about which values are more likely, a different distribution (normal, exponential, beta, etc.) would be more appropriate.
How is the variance formula (b-a)^2/12 derived?
Variance is E(X^2) - [E(X)]^2. For U(a, b): E(X) = (a+b)/2, and E(X^2) = the integral of x^2 * 1/(b-a) from a to b = (a^2 + ab + b^2)/3. Subtracting [(a+b)/2]^2 = (a^2 + 2ab + b^2)/4 gives (a^2 + ab + b^2)/3 - (a^2 + 2ab + b^2)/4. Finding a common denominator and simplifying yields (b-a)^2/12. This means variance grows with the square of the interval width: doubling the range quadruples the variance.
What is the inverse CDF (quantile function) of a uniform distribution?
The quantile function Q(p) answers the question: what value x has exactly p of the distribution below it? For U(a, b) the answer is Q(p) = a + p*(b-a). So the 25th percentile is a + 0.25*(b-a), the median is a + 0.5*(b-a) = (a+b)/2, and the 75th percentile is a + 0.75*(b-a). The quantile function is the inverse of the CDF: applying Q to p = F(x) recovers x.