Skip to main content
v2026.11,858 entries · CC-BY 4.0

Uniform Distribution Formula: PDF, Mean, Variance and Worked Example

The uniform distribution formula f(x)=1/(b-a), with mean, variance, a worked numeric example, the discrete case and R, Python and Excel code.

Written and maintained by CASRAI Editorial Board

Last updated

The uniform distribution formula for a continuous variable on the interval from a to b is f(x) = 1 / (b − a). Every value between a and b is equally likely, so the density is a flat line. This guide gives the pdf, cdf, mean and variance, one fully worked example with the arithmetic shown, the discrete case, and the parameter conventions that differ between R and SciPy.

What Is a Uniform Distribution? Definition

A uniform distribution assigns equal probability to every outcome in a range. The NIST/SEMATECH e-Handbook of Statistical Methods puts it this way: “The uniform distribution defines equal probability over a given range for a continuous distribution.” The range is set by two parameters, a lower limit a and an upper limit b, and the distribution is written X ~ Uniform(a, b) or U(a, b).

Two versions are in everyday use. The continuous uniform distribution covers every real number between a and b. The discrete uniform distribution covers a finite list of outcomes, such as the faces of a fair die. Most of this page is about the continuous case; the discrete case is covered under examples.

Uniform Distribution Formula: PDF, CDF, Mean and Variance

For X ~ Uniform(a, b) with a < b:

Quantity Formula Notes
Probability density f(x) 1 / (b − a) for a ≤ x ≤ b; 0 otherwise NIST; Pishro-Nik
Cumulative distribution F(x) 0 if x < a; (x − a) / (b − a) if a ≤ x ≤ b; 1 if x > b Derived here by integrating the pdf. NIST states the standard form, F(x) = x on [0, 1].
Mean (a + b) / 2 NIST; Pishro-Nik
Variance (b − a)² / 12 NIST; Pishro-Nik
Standard deviation (b − a) / √12 Square root of the variance
Skewness 0 NIST
Kurtosis 9/5 (excess kurtosis −6/5) NIST reports 9/5; subtracting 3 gives the excess value

What each symbol means

  • a is the minimum value the variable can take; b is the maximum.
  • b − a is the width of the interval. The density 1/(b − a) is exactly the height that makes the total area under the curve equal 1.
  • x is the value at which you evaluate the density or the cumulative probability.

The mean is the midpoint of the interval. Pishro-Nik derives the variance as E[X²] − (E[X])², where E[X²] = (a² + ab + b²) / 3, which simplifies to (b − a)² / 12. The probability that X falls between two values c and d inside the interval is simply (d − c) / (b − a): the width of the sub-interval divided by the total width.

Worked Example: Uniform(2, 10)

Suppose X ~ Uniform(2, 10), so a = 2 and b = 10.

  1. Width: b − a = 10 − 2 = 8.
  2. Density: f(x) = 1/8 = 0.125 for every x from 2 to 10.
  3. Mean: (2 + 10) / 2 = 6.
  4. Variance: 8² / 12 = 64 / 12 = 5.3333.
  5. Standard deviation: √5.3333 = 2.3094, which rounds to 2.31.
  6. P(3 < X < 5): (5 − 3) / 8 = 2/8 = 0.25.
  7. P(X ≤ 7): F(7) = (7 − 2) / 8 = 5/8 = 0.625.
  8. 90th percentile: solve (x − 2) / 8 = 0.90, so x = 2 + 0.90 × 8 = 9.2.

Check: P(X > 8) = (10 − 8) / 8 = 0.25, and P(X ≤ 8) = 6/8 = 0.75, which add to 1.

Interpretation: How to Read the Results

Result What it tells you
f(x) = 0.125 This is a density, not a probability. Any single exact value has probability 0; only intervals carry probability.
Mean = 6, median = 6 The distribution is symmetric (skewness 0), so the mean and median both sit at the midpoint.
SD = 2.31 The standard deviation depends only on the width, 8 divided by √12. Doubling the width doubles the SD.
P(3 < X < 5) = 0.25 Two units out of an eight-unit range: probability is proportional to length.
Excess kurtosis −6/5 Lighter tails than the normal distribution; there is a hard cut-off at both ends.

Uniform Distribution Examples: Continuous and Discrete

Continuous: random numbers on [0, 1]

The standard uniform distribution, Uniform(0, 1), is the base case that random number generators aim to reproduce. Monte Carlo methods turn these draws into other distributions; see Monte Carlo simulation. When a null hypothesis is true and the test statistic is continuous, the resulting p-values are themselves uniform on [0, 1], a fact that underlies p-curve analysis and is why a flat histogram of p-values is the expected pattern under no effect. See also the dictionary entry for the p-value.

Discrete: a fair six-sided die

Each face 1 to 6 has probability 1/6. The mean is (1 + 2 + 3 + 4 + 5 + 6) / 6 = 21/6 = 3.5. The mean of the squares is (1 + 4 + 9 + 16 + 25 + 36) / 6 = 91/6 = 15.1667, so the variance is 15.1667 − 3.5² = 15.1667 − 12.25 = 2.9167. This is not (b − a)² / 12, which would give 25/12 = 2.0833; the continuous variance formula must not be applied to discrete outcomes.

Assumptions and Common Mistakes

  • Finite, known limits. Both a and b must be finite, and a must be less than b. In R, dunif returns NaN when min equals max.
  • Equal likelihood is an assumption, not a default. Use it when you have a reason to believe every value in the range is equally plausible. Data that cluster around a centre are better described by other models; see normality of distribution.
  • Density is not probability. f(x) = 0.125 does not mean a 12.5% chance of X = 5. Probability comes from area: width times height.
  • Endpoints do not matter. For a continuous variable P(X = a) = 0, so whether the interval is written open or closed leaves every probability unchanged.
  • Parameter conventions differ between software. R takes the lower and upper limits (min, max). SciPy takes a start and a width: loc = a and scale = b − a. Passing the upper limit as scale shifts the whole distribution.
  • Continuous and discrete variance formulas differ. See the die example above.

To test whether a sample is consistent with a uniform distribution, for example when checking a random number generator, a one-sample goodness-of-fit test against Uniform(0, 1) is the usual approach; see the Kolmogorov-Smirnov test.

How to Report a Uniform Distribution

State the distribution, its parameters, and the summary statistics you computed, and report them to a consistent number of decimals. For the worked example:

Waiting times were modeled as uniformly distributed between 2 and 10 minutes, U(2, 10), mean = 6.00, SD = 2.31. The probability of a wait between 3 and 5 minutes was 0.25.

Follow the symbol, italics and decimal conventions of the style guide your journal or institution requires. If you used a uniform distribution as a prior or as a sampling assumption, say so and give the limits, so the reader can reproduce the calculation.

How to Calculate It in Excel, R or Python

Excel

Put a in cell B1 and b in cell B2, then use ordinary cell formulas:

Density:   =1/(B2-B1)
Mean:      =(B1+B2)/2
Variance:  =(B2-B1)^2/12
SD:        =SQRT((B2-B1)^2/12)
P(c<X<d): =(d-c)/(B2-B1)
Random draw: =B1+RAND()*(B2-B1)

With a = 2 and b = 10 these return 0.125, 6, 5.3333, 2.3094, 0.25 for c = 3 and d = 5, and a random value between 2 and 10.

R

dunif(5, min = 2, max = 10)                      # 0.125
punif(5, 2, 10) - punif(3, 2, 10)                # 0.25
qunif(0.9, 2, 10)                                # 9.2
(10 - 2)^2 / 12                                  # 5.3333
runif(5, min = 2, max = 10)                      # five random draws

The R manual documents dunif, punif, qunif and runif, with defaults min = 0 and max = 1.

Python (SciPy)

from scipy.stats import uniform
u = uniform(loc=2, scale=8)        # Uniform on [2, 10]
u.pdf(5)                           # 0.125
u.cdf(5) - u.cdf(3)                # 0.25
u.mean(), u.var(), u.std()         # 6.0, 5.3333, 2.3094
u.ppf(0.9)                         # 9.2
u.rvs(size=5)                      # five random draws

The SciPy documentation states that, using loc and scale, one obtains the uniform distribution on [loc, loc + scale].

Frequently Asked Questions

What is a uniform distribution?

A uniform distribution is a probability distribution in which every value in a stated range is equally likely. For a continuous variable on [a, b] the density is a constant 1/(b − a); for a discrete variable each of n outcomes has probability 1/n.

What is the formula for a uniform distribution?

The probability density is f(x) = 1/(b − a) for a ≤ x ≤ b. The mean is (a + b)/2 and the variance is (b − a)²/12.

What are examples of a uniform distribution?

A fair die (discrete, probability 1/6 per face), a random number generator drawing from [0, 1] (continuous), and p-values under a true null hypothesis with a continuous test statistic.

How do you find the probability between two values?

Subtract the lower value from the upper value and divide by b − a. For Uniform(2, 10), P(3 < X < 5) = 2/8 = 0.25.

Is the uniform distribution the same as a normal distribution?

No. The uniform distribution is flat with sharp limits and excess kurtosis of −6/5; the normal distribution is bell-shaped with unbounded tails. Averages of many uniform draws approach a normal shape, as described in the central limit theorem guide.

Sources

Follow CASRAI

Research-administration guidance, standards updates and independent tool reviews.

Ask CASRAI · free to try

Ask about Uniform Distribution Formula: PDF, Mean, Variance and Worked Example

Ask your first 2 questions free below. Subscribers get 150 a day for $29 a month.

An AI assistant specialized in research administration. It cites the sources behind every answer, labels web answers and says when it can't answer.

Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.

Works on this site and inside Claude, Cursor and the AI tools you already use.

Everything CASRAI publishes — this page, the dictionary, the guides and the news — stays free to read, with no account and no card.

Referenced across the research world

University of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logoUniversity of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logo
  • University of Cambridge logo
  • Columbia University logo
  • Crossref logo
  • University of Edinburgh logo
  • Harvard University logo
  • University of Oxford logo
  • Princeton University logo
  • Stanford School of Medicine logo
  • University College London logo
  • ORCID logo

View CASRAI adoption →

Ask CASRAI · Regulatory Radar

Research-admin question? Get an answer that links its sources.

An AI assistant specialized in research administration. Every answer links its sources to check before you act. 2 questions free, no account. $29/month after.

  • Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.
  • Every answer numbers its sources and links each one, so you can check the source yourself.