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:
random.shuffle(self.contents);
for _ in range(num):
results.append(self.contents.pop())
.261 every time. I finally saw that the tests and main.py 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)
results.append(self.contents[random_num])
self.contents.pop(random_num)
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: