I wasn't sure if the randomization is decent on this. It seems to be around the same percentage every time. Which could mean that the theory is proving true, but I'm not quite convinced just yet. What do you guys think?
/* ____________________________________________________
( Monty Hall Dilemma by Ruben/nnxion - Rubenisme.com )
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ */
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int chooseprize()
{
int prize;
prize = rand() % 3;
return prize;
}
int chooserandom()
{
int chosen;
srand(time(NULL) + rand() % time(NULL));
chosen = rand() % 3;
return chosen;
}
int showbad(int prize)
{
int n, bad;
srand(time(NULL) + rand() % time(NULL));
n = rand() % 2;
switch(prize)
{
case 0: if(n == 0) bad = 1; else bad = 2; break;
case 1: if(n == 0) bad = 0; else bad = 2; break;
case 2: if(n == 0) bad = 0; else bad = 1; break;
}
return bad;
}
int main()
{
int prize, chosen, bad, tried, tries, counter = 0;
float percentage = 0.00;
/* set number of tries */
tries = 5000;
/* take initial random seed */
srand(time(NULL));
for(tried = 0; tried < tries; tried++)
{
/* choose a door where the prize is behind */
prize = chooseprize();
/* choose a random door */
chosen = chooserandom();
/* show ANOTHER door with no prize */
bad = showbad(prize);
/* raise counter if it would have been good to change */
if(chosen == bad || chosen != prize) counter++;
}
percentage = ((float)counter/(float)tries) * 100;
printf("The number of times it would have been beneficial to change: %d\n", counter);
printf("The number of tries = %d, the percentage is %.2f\n\n", tries, percentage);
}