Problem 1¶
Random Dice
In this exercise, you will investigate the techniques used to generate random numbers in Python using random dice as an example.
Tasks¶
Define a function that generates the outcome of a single random 6-sided die throw.
Generate a large number of die throws and plot a histogram of the outcomes.
Plot the joint and marginal histograms for two 3-sided dice on a single plot.
Plot the joint and marginal histograms for one of the two 3-sided dice and their sum.
Write a second function which calls your first function to generate the sum of multiple die throws.
Write a function which can generate the expected probabilities (i.e. find the probability distribution) of the sum of multiple dice.
Plot a bar plot showing the both the sampled (numerical, simulated) outcomes and expected probabilities for two 4-sided dice.
Extend the functions to handle multiple dice with different numbers of sides (if you haven’t done so already), and generate samples and the expected distribution for the sum of 6, 8, and 10 sided dice. As before, visualise these using a bar plot.
Write functions to compute the mean and standard deviation of the sum of N-sided dice. Use these to compare the sample statistics to the analytical results for the previous exercise.