# Session 5: Probability - Module A: Writing an Unfair Dice Program

## 1. Overview

Modify a Python program to make unfair dice.

## 2. Setting Up

2. Open fairDice.py in gedit to view and edit the program.

Start IPython:

1. Open a terminal window.
2. Change the directory to your programs directory with the cd command.
3. Start IPython with the ipython command.
4. From IPython, you can run your program by typing run fairDice.py.

## 3. Modifying the Dice Program

Currently, the dice program you used in the previous module randomly selects numbers with equal probability. Imagine that you now want a certain number to be rolled more often than the others. Examine the fairDice program again. Can you find the line where the random number is chosen?

Try to change the program so that the number 2 is rolled twice as often as the number 3. How would you make the number 2 be rolled three times as often? Do you think you could make the numbers show up with increasing probability? Try to make the number 1 have the lowest probability and the number 6 have the highest probability.

## 4. Testing Your Program with a Histogram

To visualize the results of the rolls, change the histogram variable from `False` to `True`. Was your attempt at changing the probabilities successful?

You can also check the results of each individual roll by viewing the log file rolls.log.

Don't forget to save the histogram for your web page - you can also save a screenshot of your code! Remember to answer the questions on this page.