Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!thunder.mcrcim.mcgill.edu!snorkelwacker.mit.edu!bionet!agate!linus!philabs!ttidca!kevin From: kevin@ttidca.TTI.COM (Kevin Carothers) Newsgroups: alt.sources Subject: Re: LOTTO computer easy-pick lottery numbers generator Keywords: lotto, lotteries, Keno, drand48(), Lucky 13, RNG Message-ID: <22647@ttidca.TTI.COM> Date: 14 Jan 91 19:03:58 GMT References: <388@tnl.UUCP> <7457@minyos.xx.rmit.oz.au> <1991Jan12.171423.5842@jpradley.jpr.com> Organization: Citicorp/TTI, Santa Monica Lines: 88 In article <1991Jan12.171423.5842@jpradley.jpr.com> jpr@jpradley.UUCP (Jean-Pierre Radley) writes: %In article <7457@minyos.xx.rmit.oz.au> Michael Barnett writes: %>norstar@tnl.UUCP (Daniel Ray) writes: %> %> %> >source code. Presumes that you have the drand48() C function. %> %>I'd like to, but where do I find the drand48() C function, or is that a dumb %>question? % % %It's been part of the C library on all the *nix that I've run for the last %eight years. this lotto generator didn't make it here. Here's one I cooked up. I have my own random generator that I snarfed out of D. Knuth Vol 3 (remember that one ? :-) which seems to be "random enough". Just whack at it a little to tailor it to the game of your choice. Wrote it on a SUN. Should be fairly transportable (no serious lint errors). -------------------------------------------------------------------- #include #include #include #define xrand(x) ((x * 1103515245 + 12345) & 0x7fffffff) #define SIZE (sizeof nums / sizeof(nums[0])) int Cnt = 0; main(argc,argv) int argc; char *argv[]; { int j, i, k, seed; struct timeb *tp; long time(); int nums[6]; int tnbr; extern int errno; for(k=0; k<((argc==2)?argc:1); k++) { seed = (int) time(&tp); printf("Lucky lotto number is: "); for (i=0; i < SIZE; i++) { *(nums+i) = 0; grand(&seed,&nums[0], i); } for(i=0; i < SIZE; i++) for(j=0; j < i; j++) if(nums[j]>nums[i]) { tnbr = nums[j]; nums[j] = nums[i]; nums[i] = tnbr; } for(i=0; i < SIZE; i++) { printf("%d%s",nums[i],((i<5)?"-":" ")); nums[i] = 0; } printf("\n"); } } grand(seed, pnbr, start) int *seed; int *pnbr; int start; { int i, j, nbr; nbr = 0; while (!nbr) { nbr = *seed = (int) (xrand(*seed) % 54); } for(j=0; j<=start; j++) { if ((nbr == *(pnbr+j)) && (*(pnbr+j) != 0)){ /* No duplicates */ *seed += (int) xrand(*seed); grand(seed,pnbr,start); } } *(pnbr+start) = nbr; }