CMPSCI 187: Programming With Data Structures

David Mix Barrington

Fall, 2012

Discussion Assignment #2: Throwing a Million Dice

19 September 2012

The goal of this activity was for each pair of students to:

  1. Review the basic concept of a pseudorandom generator
  2. Become familiar with the Java Random class.
  3. Write a program that counts the occurrences of each value from 2 to 12 in a million simulated tosses of two six-sided dice.
  4. Repeat the experiment using a Random object with a known seed.

The handout from class is here.

Here is a solution, written by Ravali.

Here are the results from the second experiment, with the seed 1776, along with the numbers predicted by probability theory. If we did the experiment repeatedly with different seeds, we would predict that the average of the trials for each sum would get closer and closer to this expected number.


Sum      Number of Times  Expected Number

 2            27715          27778
 3            55558          55556
 4            83682          83333
 5           111298         111111
 6           138867         138889
 7           166411         166667
 8           138570         138889
 9           111702         111111
10            83335          83333
11            55582          55556
12            27780          27778

Last modified 26 September 2011