The following illustrates how to generate sequential numbers in C# using Visual Studio 2013. Just create a class, add the class variables, and the functions and compile. It generates all the combinations for the first 5 numbers of the Powerball lottery game. It outputs sequential files with the file sizes that can be easily opened up in Notepad in a folder called Lottery Numbers All in the users My Documents. To do it for Mega Millions, you would change the following:

For Mega Millions:

Class variables:

     public const int ALL_COMBOS_SIZE = 500000;
     public const int ALL_COMBOS_LIMIT = 75;

     public int[,] all_combos = new int[ALL_COMBOS_SIZE + 1, 6];
     public int combos_total_all;
     string appPathAll = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\Lottery Numbers All";


Class functions, make the following change in function combos_find_all:

     string filename = "\\megamillionscombosall";

For Powerball:

Class variables:

     public const int ALL_COMBOS_SIZE = 500000;
     public const int ALL_COMBOS_LIMIT = 59;

     public int[,] all_combos = new int[ALL_COMBOS_SIZE + 1, 6];
     public int combos_total_all;
     string appPathAll = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\Lottery Numbers All";

Class functions:


 public void combos_find_all()
    {

        int i, j, k, l, m, n, p;
        int index1;
        int index2;
        int index3;
        int index4;
        int index5;
        string path;
        string filename = "\\powerballcombosall";
        int filecount;
  

        for (i = 1; i <= ALL_COMBOS_SIZE; i++)
        {

            for (j = 1; j <= 5; j++)
            {

                all_combos[i, j] = 0;

            }

        }

        i = 0;

        j = 1;

        filecount = 0;

        combos_total = 0;

        combos_total_all = 0;

        for (k = 0; k <= ALL_COMBOS_LIMIT - 5; k++)
        {

            for (l = 0; l <= ALL_COMBOS_LIMIT - 5; l++)
            {

                for (m = 0; m <= ALL_COMBOS_LIMIT - 5; m++)
                {

                    for (n = 0; n <= ALL_COMBOS_LIMIT - 5; n++)
                    {

                        for (p = 0; p <= ALL_COMBOS_LIMIT - 5; p++)
                        {

                            index1 = j + k;
                            index2 = index1 + 1 + l;
                            index3 = index2 + 1 + m;
                            index4 = index3 + 1 + n;
                            index5 = index4 + 1 + p;

                            if (i  ALL_COMBOS_LIMIT - 4 ||
                                      index2 > ALL_COMBOS_LIMIT - 3 ||
                                      index3 > ALL_COMBOS_LIMIT - 2 ||
                                      index4 > ALL_COMBOS_LIMIT - 1 ||
                                      index5 > ALL_COMBOS_LIMIT))
                                {

                                    i += 1;
                                    combos_total += 1;

                                    all_combos[i, 1] = index1;
                                    all_combos[i, 2] = index2;
                                    all_combos[i, 3] = index3;
                                    all_combos[i, 4] = index4;
                                    all_combos[i, 5] = index5;


                                }



                            }

                            else
                            {

                                i = 0;

                                filecount += 1;

                                if (!Directory.Exists(appPathAll))
                                    Directory.CreateDirectory(appPathAll);

                                path = appPathAll + filename + filecount.ToString() + ".txt";

                                combos_output_all(path);

                                combos_total_all += combos_total;

                                combos_total = 0;


                            }

                        }

                    }

                }

            }

        }

        filecount += 1;

        path = appPathAll + filename + filecount.ToString() + ".txt";

        combos_output_all(path);

        combos_total_all += combos_total;
                
        MessageBox.Show(combos_total_all.ToString() + " total combinations were found.");

    }



    public void combos_output_all(string path)
    {

        int i, j, count;
        string Temp;


        StreamWriter outputfile = new StreamWriter(path);

  
        Temp = "These combinations were generated from the the total possible for the 5 pick numbers for the game specified." + "\r\n" +"\r\n";
        Temp += "Rank          Numbers 1-5" + "\r\n" + "\r\n";

        outputfile.WriteLine(Temp);

        

        for (i = 1; i <= combos_total; i++)
        {
            count = i + combos_total_all;

            Temp = (count).ToString();

            if (count < 10)

                Temp += " ";

            if (count < 100)

                Temp += " ";

            if (count < 1000)

                Temp += " ";

            if (count < 10000)

                Temp += " ";


            if (count < 100000)

                Temp += " ";

            if (count < 1000000)

                Temp += " ";

            if (count < 10000000)

                Temp += " ";


            Temp += "   ";

            for (j = 1; j <= 5; j++)
            {

                if (all_combos[i, j] < 10)
                {

                    Temp += " ";

                }

                Temp += "  ";

                Temp += all_combos[i, j].ToString();

            }

            outputfile.WriteLine(Temp);

        }

        outputfile.Close();


    }

Advertisements