Probability Calculator Test Number 3

Tell us what’s happening:
Describe your issue in detail here.
So, I was trying for a long time to figure out why my code wasn’t working. I read a lot of other people’s posts on here.

My initial solution for draw was this:
for _ in range(num):

.261 every time. I finally saw that the tests and feed a specific seed to random.seed(). When I changed my code to:

for _ in range(num):
random_num = random.randint(0, len(self.contents) - 1)

This passes the tests. I believe something with how random.shuffle() is implemented causes a slight deviation from how the .272 probability was calculated. (Probably very similar to my second solution, which would pull off the exact same series of numbers as the test writer.)

Am I right and it’s just the test, or is my logic flawed? When I seeded the generator with my system’s time, I would get answers within .03-.04 of the expected. That’s the case for either solution. If I’m correct, I think the margin of error needs to be expanded to account for this, or it needs to be clearly stated to not use random.seed() or random.shuffle() in the markdown.

Your code so far

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.121 Safari/537.36

Challenge: Probability Calculator

Link to the challenge:

For some reason this got deleted. boilerplate-probability-calculator - Replit

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.