Uniform Distribution
Uniform Distribution
Definition
The Uniform Distribution (Continuous) assigns equal probability to all values in a specified interval
Purpose
- Model scenarios where all outcomes are equally likely.
- Generate random numbers for simulations (basis of random number generators).
- Serve as a non-informative prior in Bayesian Statistics.
- Baseline for comparing other distributions.
When to Use
- All values in a range are equally probable.
- No information suggests one value is more likely than another.
- Generating random samples for Monte Carlo simulations.
Theoretical Background
Notation
where
Probability Density Function (PDF)
Constant density across the interval.
Cumulative Distribution Function (CDF)
Properties
| Property | Formula |
|---|---|
| Mean | |
| Variance | |
| Median | |
| Mode | Any value in |
Standard Uniform:
Special case where
Worked Example: Waiting for a Train
A commuter train arrives every 15 minutes. You arrive at the station at a random time, so your waiting time
Questions:
- What is the probability you wait less than 5 minutes?
- What is the average (expected) waiting time?
Solution:
Parameters:
PDF height =
1. Probability wait < 5 mins (
Result: ~33.3% chance of a short wait.
2. Average Waiting Time (
Result: On average, you will wait 7.5 minutes.
Assumptions
The Uniform distribution is a model choice:
Limitations
- The "Lazy Prior" Fallacy: Assuming a distribution is uniform just because you have no data can be dangerous (the "Principle of Indifference"). Sometimes reality is bell-shaped or power-law.
- Pseudo-randomness: Computer "uniform" generators are deterministic algorithms. For cryptography, you need cryptographically secure RNGs.
- Boundary Bias: Real-world metrics rarely have hard "walls" like
and with zero probability outside.
Python Implementation
from scipy.stats import uniform
import numpy as np
import matplotlib.pyplot as plt
# Uniform on [2, 8]
a, b = 2, 8
dist = uniform(loc=a, scale=b-a) # scipy uses loc=a, scale=b-a
# Mean and Variance
print(f"Mean: {dist.mean():.2f}")
print(f"Variance: {dist.var():.2f}")
# P(3 < X < 6)
prob = dist.cdf(6) - dist.cdf(3)
print(f"P(3 < X < 6): {prob:.4f}")
# Visualize PDF
x = np.linspace(0, 10, 500)
plt.plot(x, dist.pdf(x), lw=3, label=f'Uniform({a}, {b})')
plt.xlabel('x')
plt.ylabel('Density')
plt.title('Uniform Distribution')
plt.legend()
plt.grid(alpha=0.3)
plt.show()
# Generate Random Sample
sample = dist.rvs(size=1000)
plt.hist(sample, bins=30, density=True, alpha=0.6, edgecolor='black')
plt.title('Histogram of 1000 Uniform Samples')
plt.show()
R Implementation
# Uniform on [2, 8]
a <- 2
b <- 8
# Mean
(a + b) / 2
# P(3 < X < 6)
punif(6, min = a, max = b) - punif(3, min = a, max = b)
# Visualize PDF
curve(dunif(x, min = a, max = b), from = 0, to = 10, lwd = 3,
xlab = "x", ylab = "Density",
main = paste("Uniform(", a, ", ", b, ")", sep=""), col = "blue")
# Random Sample
runif(10, min = a, max = b)
Interpretation Guide
| Scenario | Interpretation |
|---|---|
| Scenario | Interpretation |
| ---------- | ---------------- |
| Standard reference. If |
|
| Mean vs Median | In Uniform, Mean = Median. Symmetry holds. |
| Variance | Depends heavily on the range width ( |
| Constant PDF | "Flat" likelihood. Every value is equally surprising (or unsurprising). |
Related Concepts
- Normal Distribution - Uniform is the opposite (flat vs bell).
- Bayesian Statistics - Uniform used as non-informative prior.
- Monte Carlo Simulation - Random number generation.
- Discrete Uniform Distribution - For discrete outcomes (e.g., dice).