根据我读到的概率,切换门应该有大约 66% 的机会选择正确的门。下面的代码是我想出的,它输出了大约 50% 的胜利,而不是我期望的 66%。任何关于我在这里出错的地方的帮助将不胜感激。
for (int count = 0; count < 10000; count++)
{
// Chooses which door contains DAT GRAND PRIZE YO.
wDoor = rand() % 3 + 1;
// AI Contestants Door choice
aiDoor = rand() % 3 + 1;
// Using oldChoice to ensure same door isn't picked.
oldChoice = aiDoor;
// Used in determining what door to open.
openedDoor = aiDoor;
// "Open" a door that is not the winning door and not the door chosen by player.
do
{
openedDoor = rand() % 3 + 1;
}while (openedDoor != wDoor && openedDoor != aiDoor);
// Select new door between the remaining two.
do
{
aiDoor = rand() % 3 + 1;
}while (aiDoor != oldChoice && aiDoor != openedDoor);
// Increment win counter if new door is correct.
if (aiDoor == wDoor)
{
chooseAgain++;
}
}