Well, the following is an exercise that I have to use RNG with it, but I don't have any experience related to such function (RNG), so I can't understand how to relate between the program and the code at the end of the post which generates random numbers, I am kind of confused between the N & M used in the exercise, and those M & n used in the note.

I can not understand exactly the code at the end of the post.

Thank you,

-Amy

Exercise:

-------

Use a random number generator to simulate N throws of a pair of dice and to give the number of times their sums were 7 or 11. Allow the program to input N (e.g. N = 10, 100, 1000) and to repeat the simulation M runs for the same N (e.g. M = 10). For each N, find the average probability of 7 or 11 for the M runs (sum the results for the M runs and divide by M then divide by N).

Note on using the C++ Random Number Generator (RNG):

-----------------------------------------------------

This program uses random numbers generated by a Random Number Generator (RNG). The RNG in C++ is a function rand( ) that returns a random integer from 0 to 32,767. To obtain random integers from 1 through n, use rand( ) % n + 1. To obtain a random sequence you need to first initialise the RNG using the time of the machine as a seed. This is done so that we do not get the same sequence every time we run the program.

The following is an example of how to generate a random sequence of M integers with values (x) between 1 and n :

Code:#include <time.h> int i , x , n , M srand ( (unsigned) time (NULL) ); //Initialize RNG for ( i = 1; i <= M; i++) // Loop over the sequence { x = rand( ) % n + 1; // Generate a number from the sequence cout << x << endl; // Print it }