LOTTO computer easy-pick lottery numbers generator
Kevin Carothers
kevin at ttidca.TTI.COM
Tue Jan 15 06:03:58 AEST 1991
In article <1991Jan12.171423.5842 at jpradley.jpr.com> jpr at jpradley.UUCP (Jean-Pierre Radley) writes:
%In article <7457 at minyos.xx.rmit.oz.au> Michael Barnett writes:
%>norstar at 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 <stdio.h>
#include <sys/types.h>
#include <sys/timeb.h>
#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;
}
More information about the Alt.sources
mailing list