On a follow-up of Random Walker In Python, I attempt to simulate probability distribution graph of rolling two dice and adding the numbers achieved in Python using PyGame.
When rolling two dice, distinguish between them in some way: a first one and second one, a left and a right, a red and a green, etc. Let (a,b) denote a possible outcome of rolling the two die, with a the number on the top of the first die and b the number on the top of the second die. Note that each of a and b can be any of the integers from 1 through 6. Here is a listing of all the joint possibilities for (a,b):
(1,1) (1,2) (1,3) (1,4) (1,5) (1,6) (2,1) (2,2) (2,3) (2,4) (2,5) (2,6) (3,1) (3,2) (3,3) (3,4) (3,5) (3,6) (4,1) (4,2) (4,3) (4,4) (4,5) (4,6) (5,1) (5,2) (5,3) (5,4) (5,5) (5,6) (6,1) (6,2) (6,3) (6,4) (6,5) (6,6)
Note that there are 36 possibilities for (a,b). This total number of possibilities can be obtained from the multiplication principle: there are 6 possibilities for a, and for each outcome for a, there are 6 possibilities for b. So, the total number of joint outcomes (a,b) is 6 times 6 which is 36. The set of all possible outcomes for (a,b) is called the sample space of this probability experiment.
With the sample space now identified, formal probability theory requires that we identify the possible events. These are always subsets of the sample space, and must form a sigma-algebra. In an example such as this, where the sample space is finite because it has only 36 different outcomes, it is perhaps easiest to simply declare ALL subsets of the sample space to be possible events. That will be a sigma-algebra and avoids what might otherwise be an annoying technical difficulty. We make that declaration with this example of two dice.
With the above declaration, the outcomes where the sum of the two dice is equal to 5 form an event. If we call this event E, we have
E={(1,4),(2,3),(3,2),(4,1)}.
Note that we have listed all the ways a first die and second die add up to 5 when we look at their top faces.
Consider next the probability of E, P(E). Here we need more information. If the two dice are fair and independent , each possibility (a,b) is equally likely. Because there are 36 possibilities in all, and the sum of their probabilities must equal 1, each singleton event {(a,b)} is assigned probability equal to 1/36. Because E is composed of 4 such distinct singleton events, P(E)=4/36= 1/9.
In general, when the two dice are fair and independent, the probability of any event is the number of elements in the event divided by 36. (Source : http://www.math.hawaii.edu/~ramsey/Probability/TwoDice.html)
The programming language used is Python and module used in PyGame.
The complete code is in a single function dice_roll(). This function initializes the variables, rolls the dice and blits everything on pygame window.
This slideshow requires JavaScript.
Code for Two Dice Rolls Graph Simulation : Two Dice Roll Graph Simulation
Time Lapse Video : Time Lapse Video
Let me know your thoughts and suggestions or any ideas on what should I code next!
Music Player – #CodingOf208
Quiz Master – #CodingOf208
Two Dice Roll Graph Simulation in Python On a follow-up of Random Walker In Python, I attempt to simulate probability distribution graph of rolling two dice and adding the numbers achieved in Python using PyGame.