// Arup Guha
// 10/5/2011
// Written in class - an example of a simulation of a lottery.
// A ticket is an ORDERED six-tuple of positive integers less than
// or equal to 20.

#include <stdio.h>
#include <time.h>

const int NUM_SIMULATION = 100000000;

int main() {


    srand(time(0));
    int i;
    int win = 0;

    // Repeat the simulation over and over again!
    for (i=0; i<NUM_SIMULATION; i++) {

        // Generate the winning numbers randomly.
        int winners[6];
        int j;
        for (j=0; j<6; j++)
            winners[j] = rand()%20 + 1;

        // See if we hit the ticket (1,2,3,4,5,6)
        // This is equally likely as an arbitrarily chosen ticket.
        int numcorrect = 0;
        for (j=0; j<6; j++)
            if (winners[j] == j+1)
                numcorrect++;

        // We won this time!
        if (numcorrect == 6)
            win++;

    }

    // Print out the winning percentage.
    printf("Percentage of winning is %lf\n", 100.0*win/NUM_SIMULATION);
    return 0;
}

