- Continuous Uniform Distribution: For a continuous uniform distribution over the interval [a, b], the probability density function (pdf) is constant within that interval and zero outside of it. The formula for the probability density function is:
\(f(x) = \frac{1}{b – a}\)
- Discrete Uniform Distribution: For a discrete uniform distribution with (n) possible outcomes, each outcome has an equal probability of:
\(p = \frac{1}{n}\)
In Python, you can use the numpy
library to generate random numbers following a uniform distribution. For example:
import numpy as np
import matplotlib.pyplot as plt
# Generate 1000 random numbers from a uniform distribution between 0 and 1
data = np.random.uniform(0, 1, 1000)
# Plot the histogram to visualize the uniform distribution
plt.hist(data, bins=50, edgecolor='black')
plt.title('Uniform Distribution')
plt.xlabel('Random Numbers')
plt.ylabel('Probability Density')
plt.show()