Get startedGet started for free

Sampling from a discrete uniform distribution

Tom has a regular six-sided die showing the numbers one through six. In this exercise, you'll use the discrete uniform distribution, which is perfectly suited for sampling integer values with uniform distributions, to simulate rolling Tom's die 1,000 times. You'll then visualize the results!

The following have been imported for you: seaborn as sns, scipy.stats as st and matplotlib.pyplot as plt.

This exercise is part of the course

Monte Carlo Simulations in Python

View Course

Exercise instructions

  • Define low and high for use in .rvs() sampling in the next step; your distribution should include integer values from one (the lowest possible roll outcome) through six (the highest possible roll outcome) uniformly.
  • Sample 1,000 times from the discrete uniform distribution represented by st.randint with integer values one through six.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Define low and high for use in rvs sampling below
low = ____
high = ____
# Sample 1,000 times from the discrete uniform distribution
samples = ____

samples_dict = {'nums':samples}
sns.histplot(x='nums', data=samples_dict, bins=6, binwidth=0.3)
plt.show()
Edit and Run Code