Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Testing the Random Number Generator I have some beliefs about what happens when you roll two dice, but would like to test them. In random
Testing the Random Number Generator
I have some beliefs about what happens when you roll two dice, but would like to test them.
In randomhistogram.py we'll roll several pairs of dice and draw a simple histogram of the results.
sumtwodice: should generate two random integers to and return their sum.
rolldicenum: should roll num pairs of dice by calling sumtwodice and counting the number of ssss rolled. It should return a list of the count of each roll that occurred ie a list of elements that would sum to num
drawhistogramcounts: that takes the counts produced by the previous function, creates and image, draws the histogram using ImageDraw methods and returns and Image like this:
def drawhistogramcounts:
img Image.newRGBimgwidth, imgheight
return img
The main part of your program should be only imports and:
rolls
imgwidth
imgheight
ypercount rolls
xperbar
ybase
xbase
counts rolldicerolls
img drawhistogramcounts
img.savehistopng
The constants defined here mean the rectangle for the "number of t rolled" will have:
x coordinates from xbase t xperbar left to xbase t xperbar right and
y coordinates from ybase bottom to ybase countst ypercount top
This was the output of one run of my program:
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started