Random Data Distribution
📊 NumPy Random Data Distribution
NumPy provides functions to generate random numbers following different statistical distributions. This is very useful in simulations, data analysis, and machine learning.
All these functions are in the numpy.random module.
1. Uniform Distribution
Generates numbers evenly distributed over a range [low, high).
Output (example):
low→ Minimum valuehigh→ Maximum valuesize→ Number of values or shape
2. Normal (Gaussian) Distribution
Generates numbers based on bell curve with mean loc and standard deviation scale.
Output (example):
loc→ Meanscale→ Standard deviationsize→ Output shape
3. Binomial Distribution
Simulates success/failure experiments, e.g., coin toss.
Output (example):
n→ Number of trialsp→ Probability of success
4. Poisson Distribution
Used for count of events in a fixed interval.
Output (example):
lam→ Expected number of events
5. Exponential Distribution
Simulates time between events.
scale→ 1 / rate parametersize→ Number of samples
6. Multinomial Distribution
Used for multiple categorical outcomes.
Output (example):
n→ Number of trialspvals→ Probabilities for each categorysize→ Number of experiments
7. Shuffle & Permutation
shuffle()→ Shuffle in placepermutation()→ Return shuffled copy
8. Seeding Random Generators
🧠 Summary Table of Common Distributions
| Function | Distribution | Parameters |
|---|---|---|
uniform() | Uniform | low, high, size |
normal() | Gaussian | loc, scale, size |
binomial() | Binomial | n, p, size |
poisson() | Poisson | lam, size |
exponential() | Exponential | scale, size |
multinomial() | Multinomial | n, pvals, size |
shuffle() | Shuffle | array |
permutation() | Shuffled copy | array |
🎯 Practice Tasks
Generate 1000 random numbers from normal distribution (mean=50, std=5)
Simulate coin flips 10 times for 50 trials
Generate 5 random arrays following Poisson distribution (lam=3)
Shuffle a 1D array of 20 elements
