Session 11 Dice Roll Simulator

Published

July 23, 2026

Simulating a dice roll and keeping track of the number of times each face appears was assigned to home work in session 10. We reviewed the logic, the pseudocode and the python implementation that each of the students came up with.

We then discussed the case of rolling two dice and counting the sums of the two dice. The sums can be 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 or 12. We discussed how many ways each sum can occur and what the relative frequencies of each sum are.

Two dice roll expectations

With coin toss, the expectation is that we will reach 50:50 over a large number of tosses.

With dice toss, the expectation is - each number (1-6) should appear with equal frequency over a large number of rolls.

When you toss two dice, what happens?

The possible sums are - 2,3,4,5,6,7,8,9,10,11,12 The different ways these sums can occur are:

2 - 1 way (1,1) 3 - 2 ways (1,2), (2,1) 4 - 3 ways (1,3), (2,2), (3,1) 5 - 4 ways (1,4), (2,3), (3,2), (4,1) 6 - 5 ways (1,5), (2,4), (3,3), (4,2), (5,1) 7 - 6 ways (1,6), (2,5), (3,4), (4,3), (5,2), (6,1) 8 - 5 ways (2,6), (3,5), (4,4 ), (5,3), (6,2) 9 - 4 ways (3,6), (4,5), (5,4), (6,3) 10 - 3 ways (4,6), (5,5), (6,4) 11 - 2 ways (5,6), (6,5)
12 - 1 way (6,6)

Relative frequencies of sums of two dice: - 2 - 1/36
- 3 - 2/36 - 4 - 3/36 - 5 - 4/36 - 6 - 5/36
- 7 - 6/36 - 8 - 5/36 - 9 - 4/36 - 10 - 3/36 - 11 - 2/36 - 12 - 1/36

Home work

  • Write a program to simulate rolling two dice (N) times. The program must count how many times each sum (2-12) occurs. After all rolls are completed, the program should also calculate the fraction of rolls that resulted in each sum. These fractions are examples of an empirical distribution, meaning a distribution based on observed outcomes from data or simulation.

  • Write a program to identify and print all the primes in a given range

  • Modify the two dice roll program to keep track of the number of times each sum occurs with different number of total dice rolls. Can this be printed as a table for easy comparison?

For each program write the logic, pseudocode and python implementation. If there are lines in the program you do not understand, ask AI and try to understand, otherwise, bring them to class.