Created
March 20, 2023 07:48
-
-
Save premithk/13ebba86b9e043eb20c525178d3b683a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
import numpy as np | |
TRIALS = 100000 | |
URN_A = 'red', 'red', 'red' , 'red' , 'black', 'black', 'black' | |
URN_B = 'red', 'red', 'red' , 'red' , 'red', 'black', 'black', 'black', 'black' | |
URN_C = 'red', 'red', 'red' , 'red' , 'black', 'black', 'black', 'black' | |
success = 0 | |
for i in range(TRIALS): | |
ballFromA = random.choice(URN_A) | |
ballFromB = random.choice(URN_B) | |
ballFromC = random.choice(URN_C) | |
selected_balls = [ballFromA, ballFromB, ballFromC] | |
if selected_balls.count('red') == 2: | |
success += 1 | |
print("Probability from calculation =", np.round(17/42, 2)) | |
print("Probability from monte carlo simulation =", np.round(success/TRIALS,2)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment