Contents

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

  1. Define a function that generates the outcome of a single random 6-sided die throw.

  2. Generate a large number of die throws and plot a histogram of the outcomes.

  3. Plot the joint and marginal histograms for two 3-sided dice on a single plot.

  4. Plot the joint and marginal histograms for one of the two 3-sided dice and their sum.

  5. Write a second function which calls your first function to generate the sum of multiple die throws.

  6. Write a function which can generate the expected probabilities (i.e. find the probability distribution) of the sum of multiple dice.

  7. Plot a bar plot showing the both the sampled (numerical, simulated) outcomes and expected probabilities for two 4-sided dice.

  8. 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.

  9. 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.