PythiloLesson 4 of 4 · progress kept in this browser

Reproducibility with seeds

Pseudo-random numbers come from a generator that starts at a seed. The same seed gives the same sequence, so a run can be repeated exactly.

import random

a = random.Random(42)
b = random.Random(42)
print(a.random() == b.random())  # True
Your task

Write shuffled_copy(items, seed) returning a new list shuffled by random.Random(seed).shuffle. Write split_rows(rows, test_fraction, seed) shuffling a copy the same way and returning (train, test), where test is the first int(len(rows) * test_fraction) shuffled rows. Neither may change the input or the global generator.

All lessons