Simulation of Random Processes

  1. Coin Toss Experiment: A fair coin is tossed 4, 10, 100, and 10000 times in four different trials, respectively. Write a C++ program to record the number of times a head is seen in each trial. Comment on the results you program produced?
  2. Rolling of Two Dice Experiment: Write C++ program to solve the following problem:
    Two fair dice are rolled together repeatedly until the sum of the numbers on the top of the two dice is equal to 8. How many times (in average) do the two dice need to be rolled to see the sum equal to 8.
    (1) Use analytical method (probability) to calculate the average number of rollings.
    (2) Write C++ programs to simulate die rolling. The outcome of a rolling can be simulated by a random number (1-6) generated by the C++ function rand(). To obtain a fairly accurate estimate, you need to conduct 10,000 trials. Computers will do the work for you. In each trial, record the number of rollings required for a sum of 8. Upon completion, calculate the average number of rolls of all the trials conducted. Create a function that conducts a single trial and returns the number of rollings. To conduct 10,000 trials, the function will be called 10,000 times.
  3. /* Generate random numbers */
    /* Set a seed for random number generator using computer clock time */
    srand(time(NULL));
    
    int n;
    /* rand() generates a random number between 0 and MAX_RAND */
    n = rand(); 
    
    /* Use modulus operation to set a range */
    n = rand()%6 + 1; /* generate numbers between 1 and 6 inclusive */
    
  4. Submit your analysis work for 2(1) and C++ programs together with outputs.