WeCodeAcademy

Random Numbers

Create a generator with np.random.default_rng(seed). The seed makes the "random" numbers repeatable: the same seed always gives the same numbers, which is great for examples and tests. Use rng.integers, rng.random and rng.choice.

Examplepython
Open in editor »
Quick check

Why pass a seed to default_rng?

Your turn: write the code

Use seed 7 and print five dice rolls (integers from 1 to 6).

Finish the quick check (and any code exercise) to complete this lesson, or mark it done yourself.

Tip: use the left and right arrow keys to move between lessons.