Question
(1 pt) Assume that the random number generatorrandint(m,n)is uniformly distributed . This means that the probability of generating any number between m and n is
- (1 pt) Assume that the random number generatorrandint(m,n)isuniformly distributed. This means that the probability of generating any number between m and n is the same.
Suppose that Alice simulates the roll of a pair of dice by defining the roll function below, calling it twice and adding the results:
def roll(): return randint(1,6)
Bob realizes that the roll of a pair of dice results in a sum of 2 through 12, inclusive, so he simulates the roll of a pair of dice by defining the roll function below, calling it only once:
def roll(): return randint(2,12)
Are these equivalent in terms of their behavior over time as we generate roll after roll? Why or why not?
2.(2 points)
Consider the following code written for a simple game of Dungeons & Dragons. In this game, the player rolls one 20-sided die 20 times. Each time, if the value thrown is 20, we have a critical hit and keep track of it by adding 1 to critHitTotal. Similarly, if the value thrown is 1, we have a critical miss and keep track of it by adding 1 to critMissTotal
There is a logical error in the program for this game below. Explain what is wrong and show how to correct it.
from random import randint def roll(): return randint(1,20) def game(): critHitTotal = 0 critMissTotal = 0 for i in range(20): if roll() == 20: critHitTotal += 1 elif roll() == 1: critMissTotal += 1 return (critHitTotal, critMissTotal)
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