EZ Statistics

Uniform Distribution Calculator

Calculator

Parameters

Distribution Chart

Click Calculate to view the distribution chart

Learn More

Uniform Distribution: Definition, Properties, and Applications

Definition

The uniform distribution describes a probability distribution where all outcomes in an interval are equally likely to occur.

The probability density function (PDF) is given by:f(x)={1bafor axb0otherwisef(x) = \begin{cases} \frac{1}{b-a} & \text{for } a \leq x \leq b \\ 0 & \text{otherwise} \end{cases} The cumulative distribution function (CDF) is:F(x)={0for x<axabafor axb1for x>bF(x) = \begin{cases} 0 & \text{for } x < a \\ \frac{x-a}{b-a} & \text{for } a \leq x \leq b \\ 1 & \text{for } x > b \end{cases}

Properties

  • Mean: μ=a+b2\mu = \frac{a + b}{2}
  • Variance: σ2=(ba)212\sigma^2 = \frac{(b - a)^2}{12}
  • Support: [a, b]
  • Constant probability density over the interval
  • Symmetric around the mean

Applications

1. Random Number Generation

The uniform distribution is fundamental in computer science and mathematics for generating random numbers. Since every number within a specified range has an equal probability of being chosen, it forms the foundation for more complex random number generation techniques. Many programming languages and algorithms use the uniform distribution to generate random values, which are then transformed into other distributions like normal or exponential, depending on the problem at hand. This plays a critical role in simulations, cryptography, and statistical sampling.

2. Quantization Error

In digital signal processing and analog-to-digital conversion, quantization error refers to the difference between a continuous signal and its digitized representation. This error is often modeled using a uniform distribution because the error is assumed to be equally likely to occur at any point between the quantization levels. By assuming the error is uniformly distributed, engineers can design systems that minimize distortion and improve signal quality, ensuring a more accurate representation of the original signal during conversion.

3. Project Planning

In project management and planning, particularly when there's high uncertainty around task completion times, the uniform distribution is used to model situations where there are known minimum and maximum bounds but no further information about which times are more likely. For example, when estimating the completion time for a task, if the only known information is that it will take between 3 and 7 days, a uniform distribution can model the probability of completion within this time range. This is useful in scenarios with limited data or where no specific bias exists towards particular outcomes.

4. Quality Control

In manufacturing and quality control, many products are built with certain tolerances where the product is acceptable as long as it falls within a specified range. For example, if a part must be between 10 and 12 mm in width to be considered acceptable, the uniform distribution can be used to model the potential variation of the measurements. Since any value within this range is equally likely, it helps quality engineers assess the consistency of production and ensure that all produced parts meet the required specifications. This kind of modeling is essential in industries that require high precision and low defect rates.

R Code Example

library(tidyverse)

# Parameters
a <- 2  # lower bound
b <- 6  # upper bound
x1 <- 3 # lower comparison point
x2 <- 5 # upper comparison point

# Calculate probability P(x1 ≤ X ≤ x2)
p_between <- punif(x2, min = a, max = b) - punif(x1, min = a, max = b)
print(str_glue("P({x1} ≤ X ≤ {x2}) = {round(p_between, 4)}"))

# Create plot
x <- seq(a - 0.5, b + 0.5, length.out = 1000)
density <- dunif(x, min = a, max = b)
df <- tibble(x = x, density = density)

ggplot(df, aes(x = x, y = density)) +
  geom_line() +
  geom_area(data = subset(df, x >= x1 & x <= x2), 
            aes(x = x, y = density),
            fill = "blue", alpha = 0.3) +
  geom_vline(xintercept = c(x1, x2), 
             linetype = "dashed", color = "red") +
  labs(title = str_glue("Uniform Distribution U({a}, {b})"),
       subtitle = str_glue("P({x1} ≤ X ≤ {x2}) = {round(p_between, 4)}"),
       x = "x",
       y = "Density") +
  theme_minimal()

Python Code Example

import numpy as np
import pandas as pd
from scipy import stats
import matplotlib.pyplot as plt
import seaborn as sns

# Set style
plt.style.use('seaborn')

# Parameters
a = 2  # lower bound
b = 6  # upper bound
x1 = 3  # lower comparison point
x2 = 5  # upper comparison point

# Calculate probability P(x1 ≤ X ≤ x2)
p_between = stats.uniform.cdf(x2, loc=a, scale=b-a) - stats.uniform.cdf(x1, loc=a, scale=b-a)
print(f"P({x1} ≤ X ≤ {x2}) = {p_between:.4f}")

# Create plot
x = np.linspace(a - 0.5, b + 0.5, 1000)
pdf = stats.uniform.pdf(x, loc=a, scale=b-a)

# Plot
plt.figure(figsize=(10, 6))
plt.plot(x, pdf, 'b-', label='PDF')

# Shade area between x1 and x2
x_shade = x[(x >= x1) & (x <= x2)]
pdf_shade = stats.uniform.pdf(x_shade, loc=a, scale=b-a)
plt.fill_between(x_shade, pdf_shade, alpha=0.3, color='blue')

# Add vertical lines at x1 and x2
plt.axvline(x=x1, color='red', linestyle='--', alpha=0.5)
plt.axvline(x=x2, color='red', linestyle='--', alpha=0.5)

# Add labels and title
plt.title(f'Uniform Distribution U({a}, {b})')
plt.xlabel('x')
plt.ylabel('Density')

# Add probability annotation
plt.text(0.7*(b-a)+a, 0.8/(b-a), 
         f'P({x1} ≤ X ≤ {x2}) = {p_between:.4f}',
         bbox=dict(facecolor='white', alpha=0.8))

plt.grid(True, alpha=0.3)
plt.show()

Related Links

Normal Distribution Calculator

Exponential Distribution Calculator

Beta Distribution Calculator

Poisson Distribution Calculator