蒙蒂厅 %50 - %50

-2 c random

我正在尝试模拟蒙蒂大厅问题。我没有意识到任何问题,但我收到了大约 %50 %50 的输出。我知道有解释,但我无法理解这些请帮助我

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#define win 1
#define lose 0

#define yes 1
#define no 0

int main(){
    //i assume that prize is behind the first door

    srand(time(NULL));
    
    int lose_counter = 0;
    int win_counter = 0;

    for(int i = 1;i <= 10000;i++){
        int game_status;
        int chosen_door = rand() % 3 + 1;
        int choice;

        //first step that i chose a door
        if(chosen_door == 1){
            game_status = win;
        }
        else if(chosen_door == 2){
            game_status = lose;
        }
        else if(chosen_door == 3){
            game_status = lose;
        }
        
        //host says "do you want to change your door"
        choice = rand() % 2;

        if(choice == yes){
            if(chosen_door == 1 ){//this is the case i have chosen 
                                  //first door and change it after question
                game_status = lose;
            }
            
            if(chosen_door == 2 ){
                game_status = win;
            }
            
            if(chosen_door == 3 ){
                game_status = win;
            }
        }

        if(game_status == win){
            win_counter++;
        }
        else if(game_status == lose){
            lose_counter++;
        }
    }

    printf("win: %d\nlose: %d\n",win_counter,lose_counter);
    
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

for*_*818 5

不换门时获胜的机会是1/3

如果您切换机会增加到2/3

代码利用了50%的交换和50%不进行切换,的因此平均样本1/32/3出来作为0.5