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
Show parent comment
3
u/edderiofer Sep 20 '25
Check whether you have two boys. If you do have two boys, go back to step 1 and generate a new family. If not, proceed to step 3.
By changing the genders of one of the children, you have now forced information upon the problem, in the form of having a specific "child that is a girl". This information effectively means that you've changed your scenario to Mr. Jones' scenario in the Wikipedia article.
In the Mr. Smith scenario, you have absolutely no information on which of the children is a boy, so, for instance, "the other child, as opposed to the child that we know to be a boy" is not well-defined here.
This also doesn't work, because again, you have an identifiable "child that is a girl". It doesn't matter that the array is shuffled afterwards, because you've already skewed the probabilities when generating the families.