Discussion: How can we tell if a dice is really fair?
Examine the dice program code and its output.
Plot the results of the dice program.
Download fairDice.py:
Start IPython:
The fairDice program randomly picks a number from 1 to 6 and writes it to a log file, but how do we know if the program is picking each number with equal probability?
Start by running the program: examine the output produced by the program in the file rolls.log. Can you tell just by looking at the output whether the probability of rolling each number is fair? What would be a better way to visualize the data instead of looking at the text output?
Find the line in the program that contains:
counter[rollResult] = counter[rollResult] + 1
What is being counted? How can the counter be used to help us visualize the data?
Change the histogram variable from False
to True
.
After rerunning the program, can you tell if the die is fair? How can you tell?
What would happen if the number of rolls is increased? Try increasing the total number of rolls and see if your guess was correct (hint: the die was rolled 500 times).
Don't forget to save the histogram and answer these questions on your webpage!