Ejemplo n.º 1
0
/**
 *	Initialize the oRTP library. You should call this function first before using
 *	oRTP API.
**/
void ortp_init()
{
	if (ortp_initialized++) return;

#ifdef _WIN32
	win32_init_sockets();
#endif
	ortp_init_logger();
	av_profile_init(&av_profile);
	ortp_global_stats_reset();
	init_random_number_generator();

	ortp_message("oRTP-" ORTP_VERSION " initialized.");
}
Ejemplo n.º 2
0
/**
 *	Initialize the oRTP library. You should call this function first before using
 *	oRTP API.
**/
void ortp_init()
{
	static bool_t initialized=FALSE;
	if (initialized) return;
	initialized=TRUE;

#ifdef WIN32
	win32_init_sockets();
#endif

	av_profile_init(&av_profile);
	ortp_global_stats_reset();
	init_random_number_generator();
	ortp_message("oRTP-" ORTP_VERSION " initialized.");
}
int main(void)
{
  const int numDoors = 3;
  // results[0] = wins, results[1] = losses
  int results[2] = {0};
  char playAgain = 'Y';

  // Set-up RNG
  init_random_number_generator();

  // Intro to simulator
  printf("Welcome to the Monty Hall Problem Simulator!\n\n");
  printf("Monty Hall Problem:\nSuppose you're on a game show, \
and you're given the choice of three doors: Behind one door \
is a car; behind the others, goats. You pick a door, say No. \
1, and the host, who knows what's behind the doors, opens \
another door, say No. 3, which has a goat. He then says to \
you, \"Do you want to pick door No. 2?\" Is it to your \
advantage to switch your choice?\n");

  while (playAgain == 'Y' || playAgain == 'y')
  {
    // How many repeated experiments?
    int numPlays = 1;
    printf("\nHow many plays: ");
    scanf("%d", &numPlays);

    // Launch experiments
    for (int j = 0; j < numPlays; j++)
    {
      // Always start with door 1 as choice
      int choice = 0;

      // Set-up doors (2 x numDoors array)
      // first row holds winning/losing door info
      // second row holds info about whether door is open
      bool **doors = setup_doors(numDoors);

      // Open first false door that we didn't pick
      int losingDoor = 0;
      while (losingDoor == choice || doors[0][losingDoor])
      {
        ++losingDoor;
      }
      doors[1][losingDoor] = true;

      // Switch choice to other door 
      //   or the first door we didnt pick and is not opened
      //   (for experiments with more than 3 doors)
      int otherDoor = 0;
      while (otherDoor == losingDoor || otherDoor == choice)
      {
        ++otherDoor;
      }
      choice = otherDoor;

      // record results
      doors[1][choice] = true;
      if (doors[0][choice] == false)
      {
        // loss
        results[1]++;
      }
      else
      {
        // win
        results[0]++;
      }

      // clean-up memory
      destroy_doors(doors);
    }

    // print results
    printf("Times win car after switching choice: %d\n", results[0]);
    printf("Times win goat after switching choice: %d\n\n", results[1]);
    
    printf("Play Again? (Y/N): ");
    scanf(" %c", &playAgain);
  }