[can.general] Win Big

majka@ubc-anchor.UUCP (09/16/87)

OK, all you Lotto-crazed Canadians, here is your ticket to Win Big!
What you will find below is one (1) absolutely free, public domain
pseudo-random lottery number generator.  It will, on command, give
you 6 numbers in the range 1-49 (sound familiar?).  You can have
it generate any number of "tickets" by supplying a numeric argument:

	% lotto 1000

will generate 1000 lottery ticket numbers!  By default it will give
you a single "ticket".  You may specify the seed value for the random
number generator:

	% lotto -s 17

or let it default to the process id.

This program comes with NO GUARANTEE whatsoever.  It is free for you
to use and distribute as you wish.  If you find this program useful,
please send 10% of whatever you win with it to the author :-)

Marc Majka
UBC Computer Science
6356 Agricultural Rd.
Vancouver BC  V6T 1W5

Cut on the dotted line, and compile with 'cc lotto.c -o lotto'


- - - CUT - - - CUT - - - CUT - - - CUT - - - CUT - - - CUT - - - CUT - - -
/********************************************************/
/*                                                      */
/* lotto:    generates numbers for lottery draws        */
/* usage:    lotto <no. of tickets> [-s <random seed>]  */
/* compile:  cc lotto.c -o lotto                        */
/* author:   Marc Majka                                 */
/*                                                      */
/* This program is in the public domain.                */
/*                                                      */
/********************************************************/

#include <stdio.h>

main(argc,argv)
int argc;
char *argv[];
{
    int argn, seed, i, n, x, random(), hit, lotto[50];

    n = 1;
    seed = getpid();

    for (argn = 1; argn < argc; argn++) {
        if (argv[argn][0] == '-')
            switch (argv[argn][1]) {
                case '0':
                case '1':
                case '2':
                case '3':
                case '4':
                case '5':
                case '6':
                case '7':
                case '8':
                case '9': n = atoi(argv[argn] + 1); break;

                case 's': seed = atoi(argv[++argn]); break;

                default: usage();
            }
        else n = atoi(argv[argn]);
    }

    if (n <= 0) n = 1;
    srandom(seed);

    for (i = 0; i < n; i++) {
        hit = 0;

        for (x = 1; x <= 49; x++) lotto[x] = 0;

        while (hit < 6) {
            x = (random() % 49) + 1;
            if (lotto[x] == 0) {
                lotto[x] = 1;
                hit++;
            }
        }

        for (x = 1; x <= 49; x++) if (lotto[x]) printf("%2d ",x);
        printf("\n");
    }
}

usage()
{
    fprintf(stderr,"usage:   lotto [%%d] [-s %%d]\n");
    fprintf(stderr,"options: number of \"tickets\"\n");
    fprintf(stderr,"         -s random number seed\n");
    exit(1);
}