I am sure you are familiar with a typical six-sided dice, and if all else remains equal, the probability of rolling any of the numbers is simply 1 out of 6, or a probability of 0.167.
In this post, we’ll create a simple programme that mimic the random dice roll, collate the results of each roll, followed by calculating the proportion of the rolls for each possible outcome.
For this programme, 10 rolls of our dice will be simulated, with the results being stored as a list as shown – [2, 5, 1, 3, 1, 4, 4, 4, 6, 4]. The results of each outcome would also be printed out.
The occurrence of each outcome is then stored as a tuple, which is a list whose sequence cannot be changed. The proportion of each outcome is then calculated and printed.

The code for this programme is as follows:

Line 1 imports the random module from Python, which contains the random integer generator that will be used in this programme. Random numbers in Python are not completely random, in a sense that it is possible to replicate a particular sequence of random numbers being generated. This could be useful should a set of reproducible random numbers be required for simulation purposes. Line 2 calls the random.seed() function from within the random module, and by assigning it a value of 1 within the ( ) brackets the same set of random numbers, i.e. [2, 5, 1, 3, 1, 4, 4, 4, 6, 4 ], will always be obtained.
This programme is defined as a single function roll_set() from Line 5 to Line 35.
Line 6 is a variable which indicates the number of times that we will roll this dice.
Line 7 creates an empty list which we would append each of the dice roll results.
Line 9 uses a for loop to repeat the number of dice rolls as indicated in Line 6.
Line 10 uses the random module to generate a random integer with a value between, and inclusive of, 1 to 6. Line 11 stores this value into the empty list create earlier.
Line 14 prints out the number of dice rolls that was simulated. Line 15 prints out the now populated list of the results from our ten dice rolls.
Next, another empty list called occurrence is created and a for loop will be used to count the number of occurrence of each number that have been stored in the earlier dice_outcome list. Line 20 indicate that we’ll start by counting the number of ‘1’s in the list. Line 21 to 24 creates a for loop with only have six iterations as there are only six possible dice outcomes, with an increase in the number to count after each loop, and the occurrence of each number is stored in the occurrence list.
Line 27 then organises the occurrence list as a tuple, with Line 28 printing out the occurrence as [2, 1, 1, 4, 1, 1].
Lastly, Line 31 to 34 creates a third for loop (very similar to the previous for loop) to calculate the proportion of each outcome obtained from this set of 10 dice rolls, starting from the outcome ‘1’.
Line 38 then calls the roll_set() function.
As shown above, a sequence of 10 dice roll gives us a proportion of each dice roll that is rather different to the expected 0.167. How about changing the number of dice rolls to 10,000 and 1,000,000 (Line 15 and 28 have been omitted in the following print-out as it is deemed necessary) :

Yes, the proportion obtained for a larger sample size did approximates the expected value of 0.167. Also, since the random seed has been fixed, i.e. random.seed(1), the same results would be obtained by using the same seed value.
Is there any way to make the above codes more concise and elegant? Feel free to comment.