DataMuseum.dk

Presents historical artifacts from the history of:

DKUUG/EUUG Conference tapes

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about DKUUG/EUUG Conference tapes

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - metrics - download
Index: T l

⟦5f6c91831⟧ TextFile

    Length: 9116 (0x239c)
    Types: TextFile
    Names: »lotto.c«

Derivation

└─⟦b20c6495f⟧ Bits:30007238 EUUGD18: Wien-båndet, efterår 1987
    └─⟦this⟧ »EUUGD18/General/Lotto/lotto.c« 

TextFile

#include <stdio.h>

#define	DFTHIGH	49		/* Default high number of range */
#define	DFTLOW	1		/* Default low number of range */
#define	DFTNUM	6		/* Default number of numbers to pick */
#define	MAXCOL	75		/* Screen Width */

int *mixem;

char iline[512];

int high = DFTHIGH;		/* Highest Number */
int low = DFTLOW;		/* Lowest Number */
int number = DFTNUM;		/* Number of numbers to pick */
int range;			/* Range of numbers */
int numtest = 3;		/* Number of testimonials */

char *order[] = {
    "FIRST", "SECOND", "THIRD", "FOURTH", "FIFTH", "SIXTH", "SEVENTH",
    "EIGHTH", "NINTH", "TENTH"
    };

#define	MAXNUM	((sizeof order)/sizeof(char *))

char *testimony[] = {
    "The first time I used LOTTO-DROID, I won ~$!",
    "I was unemployed, in debt for ~$, but now I have a ~T and a new ~T!",
    "Before I found LOTTO-DROID, I could only DREAM of winning ~$, but now that I have it, I'm looking forward to my first ~T!",
    "I never won a thing in my life, until I won the lottery with LOTTO-DROID.",
    "With LOTTO-DROID, I have a steady annual income of ~$ for the first time in my life!",
    "I thought I was stuck with my old ~T, but with LOTTO-DROID, I can have a new one every year!",
    "I saw those people on TV win a ~T or a ~T, but I never thought it could be me. Then I won ~$ with LOTTO-DROID!",
    "My friends laughed when they saw LOTTO-DROID. Now that I have a ~T and ~$ besides... they don't laugh anymore.",
    "I was so confident that LOTTO-DROID would fulfill my wildest fantasies, I quit my job! Now I'm broke and living on welfare, but I still play, every day!",
    "I got a copy of LOTTO-DROID to buy a ~T with, and another for a ~T, and another for a ~T - the more you have, the more you win!",
    "When my clients come to me to buy a ~T, I tell them to get a copy of LOTTO-DROID first.",
    "I didn't *always* have a ~T... but it was the first thing I got after winning ~$ with LOTTO-DROID!",
    "I wouldn't give up my new ~T for anything... Thank you, LOTTO-DROID!",
    "I've got a ~T in the garage and ~$ in the bank - thanks to LOTTO-DROID."
    };

#define	NUMTESTIMONY	((sizeof testimony)/sizeof(char *))

char *things[] = {
    "Corvette","Lamborghini","home in Pebble Beach","Florida condo",
    "vacation home","ceramic dalmatian","husband","wife",
    "case of herpes","30 foot yacht","living room set",
    "mink stoll","set of clothes","Picasso","Rembrandt","Da Vinci",
    "sailboat","set of plastic silverware","selection of blue chip stocks",
    "mortgage","string of pearlys","cubic zirconia diamond","nanny",
    "live in lover","personal maid","butler","Learjet","Rolls Royce",
    "Caribbean island","five year membership in Club Med",
    "luxury suite in the PTL theme park","Presidential nomination",
    "matched pen and pencil set","rack full of wire coat hangers",
    "condo on Park Avenue","condo on Pennsylvania Avenue",
    "child on the way","seat on the stock exchange",
    "gift certificate for the Home Shopping Network",
    "thousand bags of Doritos","marijauna ranch in Nicaragua",
    "documentary of my life on PBS",
    "television station that shows the movies *I* want to watch",
    "Mac II","IBM PS/2","Amiga 2000","Atari Mega ST","Epson QX-10",
    "Rolex","meerschaum pipe","free movie rental",
    "reserved seat at the next Superbowl","Turbo Porsche",
    "\"nugget\" bracelet","platinum tooth filling","facelift",
    "stretch limo","cellular telephone","plot in Forest Lawn",
    "major Hollywood audition","cruise around the world",
    "sense of self-worth","fatal disease","reason to go on living",
    "sex change operation","embassy post in the Marines",
    "night with Gary Hart","ministry","Suzuki Samurai",
    "sumo wrestler","subscription to GiantsVision","projection TV",
    "baseball team","basketball team","NBA franchise",
    "Jazzercise membership","barrel of pickels","herd of cattle",
    "space shuttle","private jet","phone call from the President"
    };

#define	NUMTHINGS	((sizeof things)/sizeof(char *))

char *locs[] = {
    "Sydney","Melbourne","Brasilia","Juneau","Honolulu","Anchorage",
    "Fairbanks","Hartford","Rochester","Burlington, VT","Montpelier, VT",
    "Manchester, NH","Linwood, MA","Whitinsville, MA","Worcester, MA",
    "Guam","Samoa","Mariana's Trench","Fiji","Mt. St. Helens",
    "Dover, NH","Seaside, CA","Los Angeles","New York City",
    "Great Neck","Pittsburgh","Boston","Providence, RI","Buffalo",
    "somewhere in Kansas","Minneapolis","San Jose","San Francisco",
    "Freiberg","Houston","Dallas","St. Louis","Chicago","Miami",
    "Las Vegas","Nashville","Tijuana","Havana","Philadelphia",
    "San Diego","Eugene, OR","Seattle","Sacramento","Portland, ME",
    "Eureka, CA","Sunnyvale, CA","San Juan","Tibet","Beijing",
    "Cincinnatti","Lansing, MI","Cleveland","Gary, IN","Little Rock",
    "Tallahasee","Boise","Salt Lake City","Tulsa","Nebraska City"
    };

#define	NUMLOCS		((sizeof locs)/sizeof(char *))

char usage[] =

"usage: lotto [-t n] [-b n] [-n n] [-a n] [-?] [-h]\n\n\
Lotto plays any of those games where you choose several numbers, and\n\
try to match a random drawing.\n\n\
But it's more than just another random number generator - this one works\n\
on the principle that, the more you believe, the better it works! It includes\n\
a nearly infinite number of testimonials from real, actual people who have\n\
used Lotto to change their lives.\n\nSwitches:\n\n\
\t-?\tThis message.\n\
\t-h\tDitto.\n\
\t-a\tNumber of testimonials, if wanted.\n\
\t-t\tSets the top number of the range (default %d)\n\
\t-b\tSets the bottom number of the range (default %d)\n\
\t-n\tSets the number of numbers to pick (default %d, maximum %d)\n\n\
Let me know when you make your first million!\n\n";

extern int optind;			/* Used by getopt */
extern char *optarg;

extern int atoi(), getopt();
extern char *gets(), *malloc();

main(acnt,avar)
int acnt;
char *avar[];
{
    int i, ni, t;

    while((i=getopt(acnt,avar,"t:b:n:a:h?-")) != EOF){
	switch(i){
	    case 'a':
		numtest = atoi(optarg);
		if(numtest < 1) numtest = 1;
		break;
	    case 't':
		high = atoi(optarg);
		break;
	    case 'b':
		low = atoi(optarg);
		break;
	    case 'n':
		number = atoi(optarg);
		break;
	    case '?':
	    case 'h':
		printf(usage,high,low,number);
		return;
	    }
	}

    if(high < low){
	printf("The high number of the range should be >= the low number.\n");
	return;
	}

    if(number < 1 || number > MAXNUM){
	printf("Sorry, can't pick that many numbers. Must be between 1 and %d.\n",MAXNUM);
	return;
	}

    range = high-low+1;
    mixem = (int *)malloc(sizeof(int) * range);

    if(!mixem){
	printf("Couldn't allocate enough memory for the numbers!\n");
	return;
	}

    srand(time(0L));			/* Randomize */

    printf("LOTTO-DROID\n\n");
    printf("Win the lottery the way the experts do!\n\n");

    if(yesno("Do you want to hear some testimonials from REAL PEOPLE? ")){
	printf("\n");
	for(i=0; i<numtest; ++i){
	    testify();
	    printf("\n");
	    }
	}

    printf("\nPut the power of RANDOM NUMBERS to work FOR YOU!\n");
    printf("Can %d lottery winners be wrong? You decide!\n\n",rnd(10000));

    while(!yesno("Do you believe? "))
	printf("RANDOM NUMBERS only work if YOU BELIEVE!\n");

    printf("\n");

    if(yesno("Do you REALLY believe? "))
	printf("Don't tell me, tell them RANDOM NUMBERS!\n\n");
    else
	printf("Deep in your heart, I KNOW you believe!\n\n");

    for(i=0; i<range; ++i) *(mixem+i) = i;

    for(i=0; i<range; ++i){
	ni = rnd(range);
	t = *(mixem+i);
	*(mixem+i) = *(mixem+ni);
	*(mixem+ni) = t;
	}

    printf("I can FEEL the POWER commin' over me....");
    fflush(stdout); sleep(1);
    printf("It's the POWER of RANDOM NUMBERS!\n\n");

    for(i=0; i<number; ++i){
	sleep(1);
	printf("Your %s number is %d!\n",order[i],*(mixem+i)+low);
	}

    sleep(1);
    printf("\nI BELIEVE! you will win!\n");
}

yesno(s)
char *s;
{
    char *s1;

    for(;;){
	printf("%s",s);
	s1 = gets(iline);
	if(!s1) return(0);
	if(iline[0] == 'y' || iline[0] == 'Y') return(1);
	if(iline[0] == 'n' || iline[0] == 'N') return(0);
	printf("Yes or No! ");
	}
}

int col=0;
char token[80];

testify(){
    sprintf(iline,"%s - %c.%c., %s.",testimony[rnd(NUMTESTIMONY)],
				rnd(26)+'A', rnd(26)+'A',
				locs[rnd(NUMLOCS)]);
    tokenize(iline);
    if(col){
	printf("\n");
	col = 0;
	}
}

int isspace(ch)
int ch;
{
    return(ch == ' ');
}

int rnd(n)
int n;
{
    return((rand() & 0x7FFF) % n);
}

tokenize(s)
char *s;
{
    char tmptok[80];
    char *s1;
    int l;

for(;;){

    while(isspace(*s)) ++s;
    if(!*s) return;
    for(s1=token; *s && !isspace(*s);) *s1++ = *s++;
    *s1++ = ' ';
    *s1 = 0;
    l = (s1-token);
    if(l > 1 && token[0] == '~'){
	switch(token[1]){
	    case '$':
		sprintf(tmptok,"$%d%02d.00",rnd(10000),rnd(100));
		break;
	    case 'T':
		strcpy(tmptok,things[rnd(NUMTHINGS)]);
		break;
	    default:
		strcpy(tmptok,">>WHOOPS<<");
		break;
	    }
	strcat(tmptok,&token[2]);
	tokenize(tmptok);
	continue;
	}
    if((col + l) > MAXCOL){
	printf("\n");
	col = 0;
	}
    printf("%s",token);
    col += l;
    }
}