/* This program is designed to pick out random lotto numbers from 1 to RANGE, as defined below. Normally you would think drawing random numbers in a lottery wouldn't be a problem, however you cannot draw the same number twice. So there must be a mechanism to make sure the numbers already drawn are excluded from the pool of available numbers. Here I solve the problem by bulidng an array -- essentially an array of lotto balls. The array is initialized to zeros and when a ball is drawn a 1 is stuck in its place. When future balls are drawn, the program checks the array to see if a 1 is in that ball's position. If not, the ball can be drawn. */ #include #include #include //for the seedrnd() function #define RANGE 50 //number of numbers #define BALLS 6 //number of balls to draw #define DELAY 1000000 //delay interval between picks int rnd(int range); void seedrnd(void); void main() { int numbers[RANGE]; //array that holds the balls int i,b; unsigned long d; //delay variable /* set things up */ printf("L O T T O P I C K E R\n\n"); seedrnd(); //seed the randomizer /* Initialize the array by filling every element with a zero. This means none of the balls have been drawn yet */ for(i=0;i