M11) Seed inside a loop

The program in Listing 1 is meant to simulate five rolls of a die, so that anyone who runs it gets the same five rolls.

random.seed(42) puts Python’s random-number generator in a fixed starting state. random.randint(1, 6) draws one integer from 1 through 6, including both endpoints. append adds each draw to rolls.

Listing 1: Simulating five die rolls with a seed (Question 1).
import random

# Collect the die outcomes.
rolls = []

for repetition in range(5):
    random.seed(42)
    rolls.append(random.randint(1, 6))

print(rolls)

Which statement describes the list that the program prints?

  • The five values can differ, and every run prints the same list.
  • The five values are all equal, and every run prints the same list.
  • The five values are all equal, and each run prints a different list.
  • The five values can differ, and each run prints a different list.