// Show how to generate pseudo-random numbers

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

void tenRandoms (void)
{
    int i;
    
    printf ("10 random numbers: ");
    for (i = 0; i < 10; i++)
        printf (" %d", rand());
    printf ("\n");
}

int main (void)
{
    int i, j;

    printf ("Show how to use C's built-in pseudo-random number generator\n\n");

    printf ("Without seeding first...\n");
    for (j = 0; j < 3; j++)
        tenRandoms ();

    printf ("\nNow, seeding first...\n");
    for (j = 0; j < 3; j++)
    {
        srand (1234);
        tenRandoms ();
    }

    printf ("\nNow, using time() to seed...\n");
    for (j = 0; j < 3; j++)
    {
        struct tm tm;
        srand (time (&tm));
        tenRandoms ();
    }

    printf ("\nNote that each time you RUN this program the FIRST\n");
    printf ("of the random numbers is the same...\n");
    printf ("This is because the C runtime library does an implicit srand.\n\n");
    printf ("Note that the first number in the last sequence of numbers ALWAYS is different\n");
    printf ("when you rerrun the program.\n");
    printf ("This is because we're using the runtime clock as the seed.\n");

    getchar ();
    return 0;
}
