I've written code to simulate drawing without replacement from an urn containing a different numbers of orbs of different colors. It uses random sampling. However, I need to double-check that the "correct" answer I was shown is correct, since my simulator gives something different.
My urn is
- [3 blue, 2 red, 6 green]
I am drawing 4 orbs without replacement
My event is
- [2 blue, 1 green]
This experiment is repeated 100 times, and I need to have at least the orbs in the event.
The expected probability is $27.2\%$. This site says there are 81 possibilities and lists 71 of them https://www.mathepower.com/en/urn.php . I can't figure out why I'm getting a probability of above 70%.
- Is the expected probability accurate?
- What might be the issue in my code logic (given below)?
logic (psuedo code)
run_experiment ==
set trials = []
do this 1000 times:
copy the original Urn
draw 4 from the urn randomly without replacement (uses Python random.sample(maxint, num_to_take))
put that result in the trials container/list
expected = bl bl gr
matching = []
things_that_match = [item from expected in item in one trial] e.g. [bl] or [gr] or [bl gr] etc
make a list (call it eval) containing the 1000 lists of things_that_match
make a new list containing True if things_that_match == expected, for every item in eval
sum the trues
trues/1000 = probability of
bl bl gr in 1000 trials of pick 4 from urn [3 blue, 2 red, 6 green] without replacement
code: https://gist.github.com/QuantVI/79a1c164f3017c6a7a2d860e55cf5d5b

Solved: https://stackoverflow.com/questions/71277539/too-many-copies-poor-comparison-urn-probability-problem/71279128#71279128
Issue was with how matches were being confirmed. I couldn't fix the logic, so I resorted to changing the data structure involved to do the comparison. I was able to an approximate close to 27% (since there are only 1000 trials in the simulation).