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):

[1.23 7.45 3.67 0.89 9.12]
  • low → Minimum value

  • high → Maximum value

  • size → Number of values or shape


 2. Normal (Gaussian) Distribution

Generates numbers based on bell curve with mean loc and standard deviation scale.


Output (example):

[0.45, -0.88, 1.23, 0.67, -1.12]
  • loc → Mean

  • scale → Standard deviation

  • size → Output shape


 3. Binomial Distribution

Simulates success/failure experiments, e.g., coin toss.


Output (example):

[5 6 4 7 5]
  • n → Number of trials

  • p → Probability of success


 4. Poisson Distribution

Used for count of events in a fixed interval.


Output (example):

[2 4 3 1 5]
  • lam → Expected number of events


 5. Exponential Distribution

Simulates time between events.


  • scale → 1 / rate parameter

  • size → Number of samples


 6. Multinomial Distribution

Used for multiple categorical outcomes.


Output (example):

[[1 3 6]
[2 4 4]
[3 2 5]
[0 2 8]
[2 3 5]]
  • n → Number of trials

  • pvals → Probabilities for each category

  • size → Number of experiments


 7. Shuffle & Permutation

  • shuffle() → Shuffle in place

  • permutation() → Return shuffled copy


 


 8. Seeding Random Generators



🧠 Summary Table of Common Distributions

FunctionDistributionParameters
uniform()Uniformlow, high, size
normal()Gaussianloc, scale, size
binomial()Binomialn, p, size
poisson()Poissonlam, size
exponential()Exponentialscale, size
multinomial()Multinomialn, pvals, size
shuffle()Shufflearray
permutation()Shuffled copyarray

🎯 Practice Tasks

  1. Generate 1000 random numbers from normal distribution (mean=50, std=5)

  2. Simulate coin flips 10 times for 50 trials

  3. Generate 5 random arrays following Poisson distribution (lam=3)

  4. Shuffle a 1D array of 20 elements

You may also like...