LOTTO computer easy-pick lottery numbers generator

Daniel Ray norstar at tnl.UUCP
Fri Jan 4 17:48:49 AEST 1991


Below is a quick-hack lotto program, for use in the widely popular Keno-based
state and provincial lotteries. Remember to set the two #define statements to
reflect the popular game in your locality. Defaults can be overridden on the
command line. Can be used either for Lotto or Keno. The man page follows the
source code. Presumes that you have the drand48() C function.

Enjoy.

dan ray
admin the northern lights
(currently offline, in transit to a new place and a new life)
P.S. DONT SEND ME EMAIL. BY THIS SUNDAY JAN 6, TNL WILL BE OFF THE AIR FOR
A FEW MONTHS WHILE I MOVE BACK TO THE U.S. AND LOOK FOR ANOTHER JOB.

---------------------------------couper ici----------------------------------
/*
 *   LOTTO - Keno-type lottery numbers generator, v1.0 4-January-1991
 *   by Daniel Ray, sysop of The Northern Lights (previously of Montreal, PQ)
 *
 *   THIS PROGRAM IS RELEASED INTO THE PUBLIC DOMAIN. NO DISTRIBUTION
 *   RESTRICTIONS EXIST WHATSOEVER.
 *
 *   All I ask is that.... if you strike it rich, remember me. You can send
 *   anything you consider appropriate to:
 *
 *   Daniel Ray
 *   C/O Denison Ray
 *   P.O. Box 255
 *   North Chatham, NY 12132
 *
 *   Usage: lotto		(uses defaults, see below)
 *          lotto 60            (change highest number to 60, same no. choices)
 *          lotto 80 10         (chooses 10 numbers from 1-80 for Keno)
 *
 *   Method: random number generator uses drand48(). The srand48() seeder uses
 *   the epoch time plus the previously found lotto no. (which starts as 13).
 *   If there is any magic in this, it is borrowed from the power of the
 *   number thirteen. Really a splendidly lucky number, its meaning has
 *   become perverted in Western culture to be "unlucky".
 *
 *   TO COMPILE:   cc -O lotto.c -o lotto
 */

/* Attention: define the below two numbers to match your state or province ** */

#define HIGHESTNUMBER  49
#define SELECTIONS     6    /* May want to make this 7 for 'bonus no.' lottos */

/* End of configuration section *****Leave the rest alone for luck*********** */


#include <stdio.h>

main(argc,argv)
int argc;
char **argv;
{
int		highest, numbers, loops=0, cloops=0, badchoice=0;
extern long	lrand48();
extern void	srand48();
extern long	time();
long		choice=13;		/* 13 starting seed for good luck! */
long		oldchoice[100];
	
	switch(argc) {
		case 1: highest = HIGHESTNUMBER;
			numbers = SELECTIONS;
			break;
		case 2: highest = atoi(argv[1]);
			numbers = SELECTIONS;
			break;
		case 3: highest = atoi(argv[1]);
			numbers = atoi(argv[2]);
			break;
	}
	
	/* CHECK FOR ERRORS */
	if((highest <= 0)||(numbers <= 0)){
		fprintf(stderr,"Usage: %s [highnumber] [selections]     Lotto generator program\n",argv[0]);
		exit(2);
	}
	if(highest<=numbers){
		fprintf(stderr,"%s: highnumber(%d) must be greater than %d\n",argv[0],highest,numbers);
		exit(1);
	}

	/* DRAND48() RANDOM NUMBER LOOP */
	oldchoice[0] = 0;
	while(loops < numbers){
		srand48(time((long *)0)+choice);
		choice = lrand48() % highest + 1;
		
		/* CHECK FOR DUPLICATIONS */
		while(loops > cloops){
			if(oldchoice[cloops] == choice){
				badchoice = 1;
			}
			cloops++;
		}
		if(badchoice != 1){
			oldchoice[loops] = choice;
			printf("%ld ",choice);
			loops++;
		} else {
			badchoice = 0;
		}
		cloops = 0;
	}
	
	/* FINISH PROGRAM, PRINT SELECTION LIMITS */
	printf("   [%d/%d]\n",numbers,highest);
	exit(0);
}
-----------------------------end of lotto.c; lotto.1 man page follows---------


LOTTO(1)		The Northern Lights			LOTTO(1)


Name
	lotto - Lottery numbers generator, for use in state/provincial lottos


Syntax
	lotto [highestnumber] [selections]


Description
	Lotto is a random number generator that provides possibly winning
	choices to lotto-type state or provincial lotteries. This usually
	consists of SIX different numbers between 1 and a HIGH NUMBER. The
	lottery and state or province sets the upper number, which thus
	varies depending on where you are. Lotto defaults to '49' as the
	high number, and '6' as the number of selections. You can override
	these defaults on the command line.

	The basis of "lotto" lotteries is the Las Vegas game of Keno. The
	'lotto' program can also be used to play Keno.


Method
	Lotto uses the drand48() function to generate random numbers, using
	the epoch time plus the previous random number as the seed for each
	round in the loop. Lotto will execute until it finds the necessary
	number of different values.


Errors
	The high number must be at least one more than the number of selec-
	tions, or an error message will be returned. Only nonzero integers
	less than 32676 can be entered on the command line.


LOTTO(1)		The Northern Lights			LOTTO(1)

-------------------------------thats all folks!-----------------------------



More information about the Alt.sources mailing list