Uniform Distribution
🎲 Uniform Distribution in Python
The Uniform Distribution generates random numbers that are equally likely to occur within a specified range.
It is widely used in simulations, random sampling, and scenarios where every outcome is equally probable.
✅ 1. Characteristics of Uniform Distribution
-
Continuous or discrete (NumPy supports continuous by default)
-
Parameters:
-
low→ minimum value -
high→ maximum value -
size→ number of random samples
-
-
All values between
lowandhighhave equal probability
✅ 2. Generate Uniform Data Using NumPy
Output (example):
✅ 3. Visualize Uniform Distribution
-
Histogram appears flat
-
kde=Trueadds smooth density curve
✅ 4. Change Range and Size
✅ 5. Generate 2D Uniform Array
Output (example):
🧠Summary Table
| Function | Parameters | Description |
|---|---|---|
np.random.uniform() |
low, high, size | Generates continuous uniform random numbers |
| Continuous | low=0, high=1 |
Default random floats between 0 and 1 |
| 2D array | size=(rows, cols) | Generates matrix of random numbers |
🎯 Practice Exercises
-
Generate 1000 numbers uniformly between 50–100 and plot histogram.
-
Generate 5×5 matrix of uniform random numbers between 0–1.
-
Create uniform data between -10 and 10 and compute mean and standard deviation.
