Skip to content

Instantly share code, notes, and snippets.

@misterhay
Last active April 17, 2018 19:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save misterhay/f5617baf8f7b564cd3e0e7145a4f6a90 to your computer and use it in GitHub Desktop.
Save misterhay/f5617baf8f7b564cd3e0e7145a4f6a90 to your computer and use it in GitHub Desktop.
numberOfRolls = 10
numberOfSides = 6
from random import randint # a module for random integers
resultsList = [] # create an empty list
for x in range(0,numberOfRolls): # loop through this a number of times
number1 = randint(1, numberOfSides) # pick a number between 1 and 6
number2 = randint(1, numberOfSides) # pick another number between 1 and 6
total = number1 + number2 # add those two values
#print(total)
resultsList += [total] # append the sum to the resultsList
from collections import Counter
counts = Counter(resultsList) # count how many times we got each sum
import matplotlib.pyplot as plot
plot.bar(list(counts.keys()),list(counts.values())) # create a bar graph from that count
plot.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment