Syllabus Lesson 13 of 246 · Module 1: Python for this course
Module 1: Python for this course

Random numbers you can repeat

Why it matters Networks start from random weights and shuffle their data. If you cannot repeat a run exactly, you cannot tell a real improvement from luck.

Computer random numbers come from a recipe that starts at a seed. Same seed, same sequence, every time.

rng = np.random.default_rng(42)
rng.normal(size=3)   # always the same three numbers for seed 42

Seed: the starting number for a random number generator. Fixing it makes "random" results repeatable.

Later in the course you will train the same model with five different seeds to see how much results wobble by chance alone.

Recap Make your own generator from a seed and pass it around, instead of relying on hidden global randomness.

Words and symbols in this lesson
array
a NumPy block of numbers, all the same type, that does maths on every item at once
seed
the starting number for a random generator; the same seed gives the same numbers
mean, spread
the average, and roughly how far values sit from it (standard deviation)
Your turn

Write make_data(seed, n) that builds its own generator from seed and returns n numbers from a normal distribution (mean 0, spread 1). Same seed must give identical arrays; different seeds must differ.

Spotted a problem in this lesson? Report it · Ask about this lesson

This exercise opens soon

Finish the lesson before it and this one unlocks. The whole course is free, no account needed, and you can read this lesson right now.