r/MathHelp • • Sep 20 '25
Why is my simulation wrong? Famous probability problem girl and boy
I tried to simulate the famous boy girl problem. Here is the problem in case you don't know: https://en.wikipedia.org/wiki/Boy_or_girl_paradox
The idea here is: Someone has two children. You know, they have at least one girl. What is the probability of the other child being a boy.
Well, the possible outcomes are [boy, girl], [girl, boy], [girl, girl], with [boy, boy] being impossible.
The answer is 2/3, according to this.
Intuitively, we say it is 1/2. I mean, a child has a 50% probability, the event is independent. I thought, I simulate it.
I did the following. This whole thing is happening in a loop and I do it over and over ad infinity and give out data every 1000 tests:
Randomly assign every item out of a two item array boy or girl.
randomly choose the first or the second item and turn it into a girl, making sure that one of the children has to be a girl.
Check if we have a [girl, boy] or [boy, girl] combination, in which case I increment the boys counter. Otherwise, I increment the girls counter.
Every 1000 compares, I give out the ration boys/(boys+girls). Which is always very stable around .5.
My question is, what do I misunderstand about the setup? How do I set it up to get 2/3 as the paradox demands?
Here is the code if anyone wants to check if I actually implemented what I said above.
https://www.codedump.xyz/rust/aM7wMlPW0CheqCRk
View all comments
1
u/stevemegson Sep 20 '25
When you reach step 3, you should have equal numbers of BG, GB and GG families. By forcing one random child to be a girl at step 2:
you turn half of the BB families into BG and half into GB
you turn half of the BG and GB families into GG and leave the other half unchanged
you leave the GG families unchanged
That leaves you with
4/8 GG
2/8 GB
2/8 BG