Answered step by step
Verified Expert Solution
Link Copied!

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 random_histogram.py, we'll roll several pairs of dice and draw a simple histogram of the results.
sum_two_dice(): should generate two random integers 1 to 6 and return their sum.
roll_dice(num): should roll num pairs of dice (by calling sum_two_dice) and counting the number of 2s,3s,4s,...,12s rolled. It should return a list of the count of each roll that occurred (i.e. a list of 12 elements that would sum to num).
draw_histogram(counts): 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 draw_histogram(counts):
img = Image.new("RGB",(img_width, img_height))
...
return img
The main part of your program should be only imports and:
rolls =1000
img_width =325
img_height =250
y_per_count =1000/ rolls
x_per_bar =25
y_base =230
x_base =25
counts = roll_dice(rolls)
img = draw_histogram(counts)
img.save("histo.png")
The constants defined here mean the rectangle for the "number of t rolled" will have:
x coordinates from x_base +(t -2)* x_per_bar (left) to x_base +(t -1)* x_per_bar (right) and
y coordinates from y_base (bottom) to y_base - counts[t]* y_per_count (top).
This was the output of one run of my program:

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Database Management Systems

Authors: Patricia Ward, George A Dafoulas

1st Edition

1844804526, 978-1844804528

More Books

Students also viewed these Databases questions

Question

8. Explain competency models and the process used to develop them.

Answered: 1 week ago