Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

lottery sequences number generator

Status
Not open for further replies.

glb

Programmer
Sep 6, 2000
9
0
0
GB
Hi,

Can anyone write a program to generate all (14,000,000 ish) the number sequences that could appear in the British Lotto. The program needs to generate a text file which can be exported to a database.

I guess C is the best language to do the task.

Tricky one?

Many thanks in advance.
Al
 
C (as any other programming language;) is the proper tool for this task, of course...
Alas, I don't know what's the number sequences that could appear in the British Lotto...
 
i also don't know: the British Lotto, but
look at faq205-5265

don't forget, RTFMP :) guggach
 
...this has all the hallmarks of a task where you ought first to work out why you're doing it. Do you need all those records in your database, or could you possibly get away with recording only those that are used? Very large, sparse data sets don't always need full storage.
 
Hi,

Thank you for your input. I need the whole set of numbers so I can delete from them certain sequences which I feel will not come up in the draw. Easier this way using SQL to delete the sequences than to write different programs to generate the numbers.

The British lotto chooses the 6 numbers from 1 - 49. So the program needs to generate 1,2,3,4,5,6... 1,2,3,4,5,7... 1,2,3,4,5,8 up to 44,45,46,47,48,49.

Many thanks again.
Al
 
Try this (it seems working but not optimized;) C code:
Code:
#include <stdio.h>
#include <stdlib.h>
void Print(const int* row, int m)
{
  int	i;
  if (m > 0)
  {
    for (i = 0; i < m; ++i)
    {
      if (i)
         putchar(',');
      printf("%d",row[i]+1);
    }
    putchar('\n');
  }
}

void Make(int* row, int k, int m, int lpos, int n)
{
  int j;
  if (k < m)
  {
    for (j = lpos; j <= n - m + k; ++j)
    {
      row[k] = j;
      Make(row,k+1,m,j+1,n);
    }
  }
  else
    Print(row,m);
}

void Lotto(int m, int n)
{
  int* row;

  if (n > 0 && m > 0 && m <= n)
  {
    row = (int*)calloc(sizeof(int),m);
    Make(row,0,m,0,n);
    free(row);
  }
}
/* Your case: */
Lotto(6,49);
This code generates CSV text file:
Code:
1,2,3,4,5,6
...
44,45,46,47,48,49
You may import this file into any DBMS.
Of course, it will be a huge monster. You may optimize Print() function with setvbuf() library function, or change output format etc - but it's the other story. I think it's useless work, but...
Good luck!
 
Hi,

Many thanks to all you guys, especially ArkM. I will give the code a run and have lots of coffee while the queries run later.

What a great site Tek-Tips is.

Kind regards,
Al
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top