Two Dice, One Seed

Data with PythonMedium+10 XP+10

Two Dice, One Seed

A board-game designer wants to see how often each total turns up when two dice are rolled together. The simulation must give the same counts every time it runs.

Task: write dice_totals(seed, n_rolls, sides). Each die has faces numbered from 1 to sides. Follow this exact recipe, so everyone's numbers come out the same:

  1. Make one generator: rng = np.random.default_rng(seed).
  2. Roll the first die n_rolls times with a single call to rng.integers, using size=n_rolls.
  3. Roll the second die n_rolls times with a second call to the same rng, in the same way.
  4. Roll k of the first die goes with roll k of the second. Add each pair to get a total.

Return a list of counts: how many totals were 2, how many were 3, and so on up to 2 * sides. Every total in that range gets a count, even when it is 0. If n_rolls is 0, every count is 0.

Examples

seed = 0
n_rolls = 20
sides = 6
returns [1, 1, 0, 4, 1, 4, 2, 4, 3, 0, 0]
seed = 7
n_rolls = 10
sides = 4
returns [1, 0, 1, 4, 1, 2, 1]

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run