Welcome Guest
Log In | Register )
You last visited December 8, 2016, 6:57 am
All times shown are
Eastern Time (GMT-5:00)

[C++ Code]A Quick Pick generator for PowerBall and Mega Miilions

Topic closed. 14 replies. Last post 10 years ago by LottoL.

Page 1 of 1
PrintE-mailLink
Guru101's avatar - rw6jhh
Indiana
United States
Member #48725
January 7, 2007
1953 Posts
Offline
Posted: January 19, 2007, 3:22 pm - IP Logged

I decided to make a very basic Quick Pick generator for PowerBall. It first asks how many you would like to print, picks 5 random numbers between 1 and 55(the white balls) and a random number between 1 and 42(the PowerBall). It then puts each of the white balls into numerical order and displays the results. If you want the results to be saved to a file called QuickPicks.txt, change the line that has:

//PrintToFile();        // Uncomment to print the results to QuickPicks.txt

to

PrintToFile();        // Uncomment to print the results to QuickPicks.txt 

If you want this to work with Mega Millions, change the 55's to 56's and change the 42 to 46.Cool


// Start of file

#include <iostream>
#include <iomanip>
#include <ctime>
#include <fstream>
#include <cstdlib>

using namespace std;

int Num1 = 0;
int Num2 = 0;
int Num3 = 0;
int Num4 = 0;
int Num5 = 0;
int Num6 = 0;

void SortNumbers();
void PrintToFile();

int main()
{
    srand(time(0));
    int count = 0;

    for(;;)
    {
        cout << "How many Quick Picks would you like to print(0 to quit)? ";
        cin >> count;
        cout << endl;
        if(count)
        {
            for(int i = 1; i <= count; i++)
            {
                Num1 = rand() % (55 - 1 + 1) + 1;

                do
                {
                    Num2 = rand() % (55 - 1 + 1) + 1;
                }while(Num2 == Num1);

                do
                {
                    Num3 = rand() % (55 - 1 + 1) + 1;
                }while(Num3 == Num2 || Num3 == Num1);

                do
                {
                    Num4 = rand() % (55 - 1 + 1) + 1;
                }while(Num4 == Num3 || Num4 == Num2 || Num4 == Num1);

                do
                {
                    Num5 = rand() % (55 - 1 + 1) + 1;
                }while(Num5 == Num4 || Num5 == Num3 || Num5 == Num2 || Num5 == Num1);

                Num6 = rand() % (42 - 1 + 1) + 1;

                SortNumbers();
                //PrintToFile();        // Uncomment to print the results to QuickPicks.txt

                cout << setw(2) << Num1 << " "
                     << setw(2) << Num2 << " "
                     << setw(2) << Num3 << " "
                     << setw(2) << Num4 << " "
                     << setw(2) << Num5 << " "
                     << setw(2) << Num6 << endl << endl;
            }
        }
        else
            break;
    }
    return 0;
}

void SortNumbers()
{
    int Temp = 0;
    do
    {
        if(Num1 > Num2)
        {
            Temp = Num1;
            Num1 = Num2;
            Num2 = Temp;
        }
        if(Num2 > Num3)
        {
            Temp = Num2;
            Num2 = Num3;
            Num3 = Temp;
        }
        if(Num3 > Num4)
        {
            Temp = Num3;
            Num3 = Num4;
            Num4 = Temp;
        }
        if(Num4 > Num5)
        {
            Temp = Num4;
            Num4 = Num5;
            Num5 = Temp;
        }
    }while(Num1 > Num2 || Num2 > Num3 || Num3 > Num4 || Num4 > Num5);
}

void PrintToFile()
{
    ofstream appendFile("QuickPicks.txt", ios_base::app);

    if(appendFile.fail())
    {
        cerr << "Unable to write to file." << endl;
        exit(1);
    }

    appendFile << setw(2) << Num1 << " "
              << setw(2) << Num2 << " "
              << setw(2) << Num3 << " "
              << setw(2) << Num4 << " "
              << setw(2) << Num5 << " "
              << setw(2) << Num6 << endl;

    appendFile.close();
}

 

// End of file 

    weshar75's avatar - Lottery-042.jpg
    Mcminnville, Oregon
    United States
    Member #3013
    December 13, 2003
    3052 Posts
    Offline
    Posted: January 19, 2007, 4:36 pm - IP Logged

    Lottery Post has a Quick Picks Generator in the left hand margin under the title "Quick Picks" for several game including Mega Millions and Powerball.  I thought I would let you know.-weshar75

      Guru101's avatar - rw6jhh
      Indiana
      United States
      Member #48725
      January 7, 2007
      1953 Posts
      Offline
      Posted: January 19, 2007, 5:03 pm - IP Logged

      I already knew about that.

        TheGameGrl's avatar - character catafly.jpg
        A long and winding road
        United States
        Member #17084
        June 10, 2005
        4528 Posts
        Offline
        Posted: January 19, 2007, 6:56 pm - IP Logged

        Thank you Guru for your contribution to Lottery post. We can each learn to appreciate a little more the efforts some folks make in helping or contributing with different programs.

        ~~Is it true, Is it kind,Is it necessary. ~~~

         Thanks be to the giving numbers: 1621,912,119 02014

          Guru101's avatar - rw6jhh
          Indiana
          United States
          Member #48725
          January 7, 2007
          1953 Posts
          Offline
          Posted: January 19, 2007, 7:57 pm - IP Logged

          Thank you Guru for your contribution to Lottery post. We can each learn to appreciate a little more the efforts some folks make in helping or contributing with different programs.

          No problem. The real reason why I posted the code is because a quick pick generator is indeed the most basic type of lottery number generator there is, however, modifications can be made to increase your odds of winning a prize in the lottery. Now, I'm not going to just post every single one of the algorithms that I use in my own version right away because I want this to be a learning experience for the people who are interested in coming up with their own algorithms. There are literally hundreds of ways to increase your odds of winning a prize in the lottery. Of course how often you win and how much you win depends on your strategies.Big Smile


            United States
            Member #9579
            December 12, 2004
            2121 Posts
            Offline
            Posted: January 19, 2007, 8:00 pm - IP Logged

            i don't care if it's in the millions,i want a qp generator that shows us all possible combinations.then each drawing we could just check off a numerically posted sequence.like the lottery has!

              Guru101's avatar - rw6jhh
              Indiana
              United States
              Member #48725
              January 7, 2007
              1953 Posts
              Offline
              Posted: January 19, 2007, 8:43 pm - IP Logged

              i don't care if it's in the millions,i want a qp generator that shows us all possible combinations.then each drawing we could just check off a numerically posted sequence.like the lottery has!

              This will create a file that has all the combinations in it:

               // Start of file

              #include <iostream>
              #include <fstream>
              #include <cstdlib>

              using namespace std;

              int Num1 = 0;
              int Num2 = 0;
              int Num3 = 0;
              int Num4 = 0;
              int Num5 = 0;
              int Num6 = 0;

              int main()
              {
                  ofstream outFile("AllCombinations.txt");
                  if(outFile.fail())
                  {
                      cerr << "ERROR: Could not create file." << endl;
                      exit(1);
                  }
                  for(Num1 = 1; Num1 <= 51; Num1++)
                  {
                      for(Num2 = Num1 + 1; Num2 <= 52; Num2++)
                      {
                          for(Num3 = Num2 + 1; Num3 <= 53; Num3++)
                          {
                              for(Num4 = Num3 + 1; Num4 <= 54; Num4++)
                              {
                                  for(Num5 = Num4 + 1; Num5 <= 55; Num5++)
                                  {
                                      for(Num6 = 1; Num6 <= 42; Num6++)
                                      {
                                          outFile << Num1 << " "
                                                  << Num2 << " "
                                                  << Num3 << " "
                                                  << Num4 << " "
                                                  << Num5 << " "
                                                  << Num6 << endl;
                                      }
                                  }
                              }
                          }
                      }
                  }
                  cout << "Done!!!!" << endl;
                  outFile.close();
                  return 0;
              }

               // End of file

               Keep in mind if you run this, it will take a VERY VERY VERY long time to complete, so it's best that you close other running programs before running it. Also keep in mind that it could take 30 minutes or more(depending on the speed of your computer) just to open this file in notepad because the file will be 1.4GB in size!!!!!! I suggest not using other programs while the file is being opened.

                Avatar

                United States
                Member #10720
                January 23, 2005
                933 Posts
                Offline
                Posted: January 19, 2007, 9:00 pm - IP Logged

                Nice programs. I write C# which is similar. My program runs in Windows. One part of the program has an RNG option mainly to use for computerized drawings if/when I play those. Question: Does the RNG generator make sure that a number is not put twice (other than Bonus Ball)? I don't recommend using a list 1.4gb in size, that eats so much disk space! A twist on the marking off of used numbers: use your favorite RNG method and pick 5 numbers and a BB, then flag off the 5 numbers (and a separate BB list) and keep going until they run out (all #s flagged) at that point unflag all #s if you want to keep generating more. THIS IS SIMILAR TO THE METHOD A GROUP OF SCIENTISTS USED (in England or Australia I think) AND WON 8 MILLION DOLLARS (except they used pieces of paper). If you want a Windows prg. for this I can make one in minutes. In fact I might make this prg. very soon and give you a link to it. Also question, the RNG that's on here, do you need Double Secret Premium Access to use it? Or anyone can?

                  LottoL's avatar - techno eye.jpg
                  Texas
                  United States
                  Member #33719
                  February 24, 2006
                  705 Posts
                  Offline
                  Posted: January 20, 2007, 3:38 am - IP Logged

                  This will create a file that has all the combinations in it:

                   // Start of file

                  #include <iostream>
                  #include <fstream>
                  #include <cstdlib>

                  using namespace std;

                  int Num1 = 0;
                  int Num2 = 0;
                  int Num3 = 0;
                  int Num4 = 0;
                  int Num5 = 0;
                  int Num6 = 0;

                  int main()
                  {
                      ofstream outFile("AllCombinations.txt");
                      if(outFile.fail())
                      {
                          cerr << "ERROR: Could not create file." << endl;
                          exit(1);
                      }
                      for(Num1 = 1; Num1 <= 51; Num1++)
                      {
                          for(Num2 = Num1 + 1; Num2 <= 52; Num2++)
                          {
                              for(Num3 = Num2 + 1; Num3 <= 53; Num3++)
                              {
                                  for(Num4 = Num3 + 1; Num4 <= 54; Num4++)
                                  {
                                      for(Num5 = Num4 + 1; Num5 <= 55; Num5++)
                                      {
                                          for(Num6 = 1; Num6 <= 42; Num6++)
                                          {
                                              outFile << Num1 << " "
                                                      << Num2 << " "
                                                      << Num3 << " "
                                                      << Num4 << " "
                                                      << Num5 << " "
                                                      << Num6 << endl;
                                          }
                                      }
                                  }
                              }
                          }
                      }
                      cout << "Done!!!!" << endl;
                      outFile.close();
                      return 0;
                  }

                   // End of file

                   Keep in mind if you run this, it will take a VERY VERY VERY long time to complete, so it's best that you close other running programs before running it. Also keep in mind that it could take 30 minutes or more(depending on the speed of your computer) just to open this file in notepad because the file will be 1.4GB in size!!!!!! I suggest not using other programs while the file is being opened.

                  Nice Program!

                  Although I think it would be interesting to have several data sets.

                  1.  Data Set consisting of all possible combinations without the bonus ball.
                  2.  Data Set consisting of all possible combinations without the bonus ball
                      and without three consecutive numbers.  (Ex. 1,2,3)
                  3.  Data Set consisting of all possible combinations without the bonus ball
                      and without four consecutive numbers.  (Ex. 1,2,3,4)
                  4.  Data Set consisting of all possible combinations without the bonus ball
                      and without five consecutive numbers.  (Ex. 1,2,3,4,5)

                  Then using your random number generator, have the program select which data
                  set you want to use and generate a random number based on that data set.

                  Best Of Luck,

                  LottoL 

                    LottoL's avatar - techno eye.jpg
                    Texas
                    United States
                    Member #33719
                    February 24, 2006
                    705 Posts
                    Offline
                    Posted: January 20, 2007, 5:07 am - IP Logged

                    Keep in mind if you run this, it will take a VERY VERY VERY long time to complete, so it's best that you close other running programs before running it. Also keep in mind that it could take 30 minutes or more(depending on the speed of your computer) just to open this file in notepad because the file will be 1.4GB in size!!!!!! I suggest not using other programs while the file is being opened.

                    ---------------------------------------------------------------------------------------------------------------

                    I wouldn't use Notepad.
                    I would use an editor such as vedit.  http://www.vedit.com/

                    Best Of Luck!

                    LottoL

                      Guru101's avatar - rw6jhh
                      Indiana
                      United States
                      Member #48725
                      January 7, 2007
                      1953 Posts
                      Offline
                      Posted: January 20, 2007, 1:27 pm - IP Logged

                      Nice programs. I write C# which is similar. My program runs in Windows. One part of the program has an RNG option mainly to use for computerized drawings if/when I play those. Question: Does the RNG generator make sure that a number is not put twice (other than Bonus Ball)? I don't recommend using a list 1.4gb in size, that eats so much disk space! A twist on the marking off of used numbers: use your favorite RNG method and pick 5 numbers and a BB, then flag off the 5 numbers (and a separate BB list) and keep going until they run out (all #s flagged) at that point unflag all #s if you want to keep generating more. THIS IS SIMILAR TO THE METHOD A GROUP OF SCIENTISTS USED (in England or Australia I think) AND WON 8 MILLION DOLLARS (except they used pieces of paper). If you want a Windows prg. for this I can make one in minutes. In fact I might make this prg. very soon and give you a link to it. Also question, the RNG that's on here, do you need Double Secret Premium Access to use it? Or anyone can?

                      Sorry it took so long to respond. The program does make sure that duplicate numbers are not used. If you use an editor to open large files like LottoL said instead of notepad, then it will open the file MANY times faster. Notepad is very slow at opening files of that size. I opened it using Visual C++ and it opens it a whole lot faster. Find a decent editor and you should be good to go. To run the code above, all you need is a C++ compiler. Dev C++ is a free C++ compiler. Just google for it.

                        Guru101's avatar - rw6jhh
                        Indiana
                        United States
                        Member #48725
                        January 7, 2007
                        1953 Posts
                        Offline
                        Posted: January 20, 2007, 2:40 pm - IP Logged

                        Nice Program!

                        Although I think it would be interesting to have several data sets.

                        1.  Data Set consisting of all possible combinations without the bonus ball.
                        2.  Data Set consisting of all possible combinations without the bonus ball
                            and without three consecutive numbers.  (Ex. 1,2,3)
                        3.  Data Set consisting of all possible combinations without the bonus ball
                            and without four consecutive numbers.  (Ex. 1,2,3,4)
                        4.  Data Set consisting of all possible combinations without the bonus ball
                            and without five consecutive numbers.  (Ex. 1,2,3,4,5)

                        Then using your random number generator, have the program select which data
                        set you want to use and generate a random number based on that data set.

                        Best Of Luck,

                        LottoL 

                        Ok, I went ahead and made a different version to create a data set by those conditions.

                        *************************************

                        To meet condition 1, the if statement should be: if(true)

                        To meet condition 2, the if statement should be: if(!Is123())

                        ^^^Condition 2 is the version that I have posted below^^^

                        To meet condition 3, the if statement should be: if(!Is1234())

                        To meet condition 4, the if statement should be: if(!Is12345())

                        Keep in mind that if you want to keep a version of each file, make sure you make a copy of DataSets.txt with a different name(such as DataSets123.txt) because DataSets.txt is overwritten each time you run the program.

                         

                        // Start of file

                        #include <iostream>
                        #include <fstream>
                        #include <cstdlib>

                        using namespace std;

                        int Num1 = 0;
                        int Num2 = 0;
                        int Num3 = 0;
                        int Num4 = 0;
                        int Num5 = 0;
                        int Num6 = 0;

                        bool Is123();
                        bool Is1234();
                        bool Is12345();

                        int main()
                        {
                            ofstream outFile("DataSets.txt");
                            if(outFile.fail())
                            {
                                cerr << "ERROR: Could not create file." << endl;
                                exit(1);
                            }
                            for(Num1 = 1; Num1 <= 51; Num1++)
                            {
                                for(Num2 = Num1 + 1; Num2 <= 52; Num2++)
                                {
                                    for(Num3 = Num2 + 1; Num3 <= 53; Num3++)
                                    {
                                        for(Num4 = Num3 + 1; Num4 <= 54; Num4++)
                                        {
                                            for(Num5 = Num4 + 1; Num5 <= 55; Num5++)
                                            {
                                                if(!Is123())
                                                {
                                                    outFile << Num1 << " "
                                                            << Num2 << " "
                                                            << Num3 << " "
                                                            << Num4 << " "
                                                            << Num5 << endl;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            cout << "Done!!!!" << endl;
                            outFile.close();
                            return 0;
                        }

                        bool Is123()
                        {
                            if((Num1 == Num2 - 1 && Num2 == Num3 - 1) ||
                              (Num2 == Num3 - 1 && Num3 == Num4 - 1) ||
                              (Num3 == Num4 - 1 && Num4 == Num5 - 1))
                              return true;
                            else
                              return false;
                        }

                        bool Is1234()
                        {
                            if((Num1 == Num2 - 1 && Num2 == Num3 - 1 && Num3 == Num4 - 1) ||
                              (Num2 == Num3 - 1 && Num3 == Num4 - 1 && Num4 == Num5 - 1))
                              return true;
                            else
                              return false;
                        }

                        bool Is12345()
                        {
                            if(Num1 == Num2 - 1 && Num2 == Num3 - 1 && Num3 == Num4 - 1 && Num4 == Num5 - 1)
                                return true;
                            else
                                return false;
                        }

                        // End of file

                          Guru101's avatar - rw6jhh
                          Indiana
                          United States
                          Member #48725
                          January 7, 2007
                          1953 Posts
                          Offline
                          Posted: January 20, 2007, 3:06 pm - IP Logged

                          I modified the first program to generate Quick Picks based off conditions 2-4. The program will still randomly generate a PowerBall. 

                          Condition 2(^^^This is the version that I'm posting^^^):

                          do
                          {
                              PickNumbers();
                              SortNumbers();
                          }while(Is123());

                          Condition 3:

                          do
                          {
                              PickNumbers();
                              SortNumbers();
                          }while(Is1234());

                          Condition 4:

                          do
                          {
                              PickNumbers();
                              SortNumbers();
                          }while(Is12345());

                          To use none of the conditions:

                          do
                          {
                              PickNumbers();
                              SortNumbers();
                          }while(false);

                          // Start of file

                          #include <iostream>
                          #include <iomanip>
                          #include <ctime>
                          #include <fstream>
                          #include <cstdlib>

                          using namespace std;

                          int Num1 = 0;
                          int Num2 = 0;
                          int Num3 = 0;
                          int Num4 = 0;
                          int Num5 = 0;
                          int Num6 = 0;

                          void PickNumbers();
                          void SortNumbers();
                          void PrintToFile();
                          bool Is123();
                          bool Is1234();
                          bool Is12345();

                          int main()
                          {
                              srand(time(0));
                              int count = 0;

                              for(;;)
                              {
                                cout << "How many Quick Picks would you like to print(0 to quit)? ";
                                cin >> count;
                                cout << endl;
                                if(count)
                                {
                                    for(int i = 1; i <= count; i++)
                                    {
                                          do
                                          {
                                              PickNumbers();
                                              SortNumbers();
                                          }while(Is123());
                                      //PrintToFile();      // Uncomment to print the results to QuickPicks.txt

                                      cout << setw(2) << Num1 << " "
                                          << setw(2) << Num2 << " "
                                          << setw(2) << Num3 << " "
                                          << setw(2) << Num4 << " "
                                          << setw(2) << Num5 << " "
                                          << setw(2) << Num6 << endl << endl;
                                    }
                                }
                                else
                                    break;
                              }
                              return 0;
                          }

                          void PickNumbers()
                          {
                              Num1 = rand() % (55 - 1 + 1) + 1;

                              do
                              {
                                  Num2 = rand() % (55 - 1 + 1) + 1;
                              }while(Num2 == Num1);

                              do
                              {
                                  Num3 = rand() % (55 - 1 + 1) + 1;
                              }while(Num3 == Num2 || Num3 == Num1);

                              do
                              {
                                  Num4 = rand() % (55 - 1 + 1) + 1;
                              }while(Num4 == Num3 || Num4 == Num2 || Num4 == Num1);

                              do
                              {
                                  Num5 = rand() % (55 - 1 + 1) + 1;
                              }while(Num5 == Num4 || Num5 == Num3 || Num5 == Num2 || Num5 == Num1);

                              Num6 = rand() % (42 - 1 + 1) + 1;
                          }

                          void SortNumbers()
                          {
                              int Temp = 0;
                              do
                              {
                                if(Num1 > Num2)
                                {
                                    Temp = Num1;
                                    Num1 = Num2;
                                    Num2 = Temp;
                                }
                                if(Num2 > Num3)
                                {
                                    Temp = Num2;
                                    Num2 = Num3;
                                    Num3 = Temp;
                                }
                                if(Num3 > Num4)
                                {
                                    Temp = Num3;
                                    Num3 = Num4;
                                    Num4 = Temp;
                                }
                                if(Num4 > Num5)
                                {
                                    Temp = Num4;
                                    Num4 = Num5;
                                    Num5 = Temp;
                                }
                              }while(Num1 > Num2 || Num2 > Num3 || Num3 > Num4 || Num4 > Num5);
                          }

                          void PrintToFile()
                          {
                              ofstream appendFile("QuickPicks.txt", ios_base::app);

                              if(appendFile.fail())
                              {
                                cerr << "Unable to write to file." << endl;
                                exit(1);
                              }

                              appendFile << setw(2) << Num1 << " "
                                    << setw(2) << Num2 << " "
                                    << setw(2) << Num3 << " "
                                    << setw(2) << Num4 << " "
                                    << setw(2) << Num5 << " "
                                    << setw(2) << Num6 << endl;

                              appendFile.close();
                          }

                          bool Is123()
                          {
                              if((Num1 == Num2 - 1 && Num2 == Num3 - 1) ||
                                (Num2 == Num3 - 1 && Num3 == Num4 - 1) ||
                                (Num3 == Num4 - 1 && Num4 == Num5 - 1))
                                return true;
                              else
                                return false;
                          }

                          bool Is1234()
                          {
                              if((Num1 == Num2 - 1 && Num2 == Num3 - 1 && Num3 == Num4 - 1) ||
                                (Num2 == Num3 - 1 && Num3 == Num4 - 1 && Num4 == Num5 - 1))
                                return true;
                              else
                                return false;
                          }

                          bool Is12345()
                          {
                              if(Num1 == Num2 - 1 && Num2 == Num3 - 1 && Num3 == Num4 - 1 && Num4 == Num5 - 1)
                                  return true;
                              else
                                  return false;
                          }

                          // End of file

                           

                          Smile

                            Guru101's avatar - rw6jhh
                            Indiana
                            United States
                            Member #48725
                            January 7, 2007
                            1953 Posts
                            Offline
                            Posted: January 20, 2007, 4:00 pm - IP Logged

                            I would like to state that the elimination of 3 consecutive numbers in your picks is a gimme strategy when picking numbers playing the lottery. For the PowerBall:

                            Elimination of all sets that have 3 consecutive numbers when taking ONLY the five white balls into consideration covers 1.94396798% of the possible combinations(ignoring the PowerBall).

                            Elimination of all sets that have 3 consecutive numbers when taking the five white balls AND the PowerBall into consideration covers 0.0462849519% of the possible combinations(including the PowerBall).

                            So you do increase your odds, but not by much.

                              LottoL's avatar - techno eye.jpg
                              Texas
                              United States
                              Member #33719
                              February 24, 2006
                              705 Posts
                              Offline
                              Posted: January 23, 2007, 12:53 pm - IP Logged

                              I would like to state that the elimination of 3 consecutive numbers in your picks is a gimme strategy when picking numbers playing the lottery. For the PowerBall:

                              Elimination of all sets that have 3 consecutive numbers when taking ONLY the five white balls into consideration covers 1.94396798% of the possible combinations(ignoring the PowerBall).

                              Elimination of all sets that have 3 consecutive numbers when taking the five white balls AND the PowerBall into consideration covers 0.0462849519% of the possible combinations(including the PowerBall).

                              So you do increase your odds, but not by much.

                              Thanks Guru101.  I sincerely appreciate your response!


                              I'll have to download the compiler and check out
                              your programs whenever I get some free time.

                              Thanks Again!

                              Best Of Luck!
                              LottoL