0 / 34
Lesson 4

Random Arrays

Random module:

rng = np.random.default_rng(42)
rng.random((3,))        # 3 floats
rng.integers(1, 7, 5)   # 5 ints 1-6
rng.normal(0, 1, (2,3)) # normal dist

A seed makes results reproducible.

Why this matters

Train/validation splits, simulations, and initialized weights all need randomnessβ€”but reproducible randomness when you debug or share results. The Generator API is the modern, explicit way to do that.

Without a seed, "it worked yesterday" is often just a different random draw.

ResourcesDocs, references & more β€” opens in a new tab
🎯 Your Task

Seed 0. Generate rolls β€” 10 ints from 1 to 6.

rng = np.random.default_rng(0), rng.integers(1, 7, 10)
exercise.py
⌘⏎ run Β· βŒ˜β† β†’ nav
β–Ά Output
Run your code to see output here.