Block 19: Random Numbers & Simulation
Generate reproducible random data for simulations and ML.
Concepts
- np.random.seed() for reproducibility
- np.random.randint(), np.random.rand(), np.random.randn()
- Shuffling and sampling: np.random.shuffle, np.random.choice
- Generating from distributions: normal, uniform, Poisson
Code Examples
See exercise below.
Exercise
Simulate 10,000 dice rolls; count and print frequency of each face. Generate 1000 samples from N(0,1); verify mean ≈ 0 and std ≈ 1.
Homework
Write a Monte Carlo estimate of π using random points in a unit square.