1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <getopt.h>
#define randrange(N) rand() / (RAND_MAX/(N) + 1)
#define MAX 75
void getNumbers();
static int randvalue[5];
int candidates[MAX];
int x;
int main (int argc, char **argv) {
srand(time(NULL));
int pmultiplier = rand() % 15 + 1;
int gmultiplier = rand() % 15 + 1;
while ((x = getopt (argc, argv, "pgoh")) != -1)
switch (x)
{
case 'p':
getNumbers();
printf("Your numbers are: %i %i %i %i %i [%i]\n", randvalue[0], randvalue[1], randvalue[2], randvalue[3], randvalue[4], pmultiplier);
break;
case 'g':
getNumbers();
printf("The winning numbers are: %i %i %i %i %i [%i]\n", randvalue[0], randvalue[1], randvalue[2], randvalue[3], randvalue[4], gmultiplier);
break;
case 'o':
printf("5 numbers plus multiplier - 1 in 259 million (Jackpot!)\n");
printf("5 numbers - 1 in 18.5 million ($1,000,00.00)\n");
printf("4 numbers plus mulitplier - 1 in 740 thousand ($5,000.00)\n");
printf("4 numbers - 1 in 52.8 thousand ($500.00)\n");
printf("3 numbers plus multiplier 1 in 10.7 thousand ($50.00)\n");
printf("3 numbers - 1 in 766 ($5.00)\n");
printf("2 numbers plus mulitplier - 1 in 473 ($5.00)\n");
printf("1 number plus mulitplier - 1 in 56.5 ($2.00)\n");
printf("1 mutiplier - 1 in 21.4 ($1.00)\n");
break;
case 'h':
printf("Usage\n");
printf("-p pick lottery numbers\n");
printf("-g generate winning numbers\n");
printf("-o print odds and payouts\n");
printf("-h print this screen\n");
}
return 0;
}
void getNumbers(){
int i;
for (i = 0; i < MAX; i++)
candidates[i] = i;
for (i = 0; i < MAX-1; i++) {
int a = randrange(MAX-i);
int b = candidates[i];
candidates[i] = candidates[i+a];
candidates[i+a] = b;
}
for (i = 0; i < 5; i++)
randvalue[i] = candidates[i] + 1;
}
|