#include "rand.h"

int main()
{
    // YOU MUST INITIALIZE THE RANDOM NUMBER GENERATOR
    // Here are two ways to initialize the random number generator

    // new random sequence each time
    setFastRandNoSeed();  // this is required before you ask for the first
                          // random number

    // OR

    // same random sequence each time
    unsigned int seedA=3212453;  // set the random number generator to a...
    unsigned int seedB=33331;    // fixed starting point for repeatable...
    setFastRand(seedA, seedB);   // experiments.              


    // experiment 0 (just a simple call to fastRand())
    // fastRand() is the most basic fastest call.
    // IMPORTANT: It returns an unsigned 32 bit number, that is, it
    // gives you a random 32 bit string.
    for (int i=0; i<10; i++) printf("%u\n", fastRand());


    // experiment 1 (average of sum of two cubical dice rolls)
    // IMPORTANT: fastModRand(X) returns ints in the range 0 to X-1 NOT X!
    int count[13];
    for (int i=0; i<13; i++) count[i]=0;

    for (int i=0; i<10000; i++) {
	int dieA, dieB;

	dieA = fastModRand(6)+1;  // dieA is an int in range 1 to 6
	dieB = fastModRand(6)+1;  // dieB is an int in range 1 to 6

	count[dieA+dieB]++;
    }

    for (int i=0; i<13; i++) printf("%2d %d\n", i, count[i]);



    // experiment 2:  chose to increment p with probability .666
    printf("\n");

    double p;

    p = 0.0;
    for (int i=0; i<10000; i++) {
	if (fastUnitRand()<.666) p++;
    }
    printf("Is the average .666: %fl\n", p/10000);


    // experiment 3: chose between two things
    printf("\n");
    if (fastRandCoin()) printf("YES\n");
    else printf("NO\n");


    // experimetn 4:  twenty rolls of a 32 sided die labeled 0 to 31.
    // this uses the fact the 32 is a power of 2 to run faster
    // NOTE: the fastMaskRand call below could be also written:
    // fastMaskRand( (1<<5)-1 )
    printf("\n");
    for (int i=0; i<20; i++) {
	printf("%2d\n", fastMaskRand(0x1f)); // 0x1f is 11111 in binary
    }

}
