Uniform Distribution

The uniform distribution is a type of probability distribution where all outcomes are equally likely. It is commonly used in simulations and random sampling, such as generating random test scores or prices.

Key Topics

Generating Uniform Distribution

NumPy's random.uniform() function generates random numbers within a specified range, where each number has an equal probability of being chosen.

Example

# Generating uniform distribution
import numpy as np

# Generate 10 random prices between 100 and 200
prices = np.random.uniform(100, 200, 10)

print("Sample prices:", prices)

Output

Sample prices: [123.45 176.78 134.67 154.23 199.56 ...]

Explanation: The random.uniform() function generates 10 random numbers within the range of 100 to 200, simulating prices uniformly distributed across this range.

Visualizing the Distribution

You can visualize a uniform distribution using a histogram to observe the even spread of values across the specified range.

Example

# Visualizing uniform distribution
import seaborn as sns
import matplotlib.pyplot as plt

# Data
prices = np.random.uniform(100, 200, 1000)

# Plot
sns.histplot(prices, kde=False, color="blue", bins=20)
plt.title("Uniform Distribution of Prices")
plt.xlabel("Price Range")
plt.ylabel("Frequency")
plt.show()

Output

A histogram showing an even distribution of prices across the range 100-200.

Explanation: The histogram demonstrates the uniform distribution of values, where all ranges have approximately equal frequency.

Key Takeaways

  • Uniform Distribution: Models scenarios where every outcome in a range has equal probability.
  • Simulation: Use random.uniform() for random sampling or generating test data.
  • Visualization: Histograms help illustrate the even distribution of values.
  • Applications: Generate test data for simulations or pricing experiments.