• Status: Solved
• Priority: Medium
• Security: Public
• Views: 364

# Need help with writing a lottery number generator

So I have this idea...
It may have been done before, but I can't find any good examples.

I want to write a php file that goes out to the Florida Lottery website and downloads lottery data and, based off that data, generates lottery numbers.
The program should work logically something like this:

2. Calculate all winning combinations for every winning number sequence
3. figure out the most common winning numbers
4. figure out what numbers are statistically due
5. print out a "best guess" for the next winning combination.

Since all winning numbers are freely available in that pdf, and that pdf is updated every time there's a new winner, shouldn't something like this be feasible?

Can anyone help me get started?
0
cdukes
• 6
• 3
1 Solution

Author Commented:
After looking at that PDF file closer, I see that it's not just the lotto numbers, but other as well...so  would need a way to extract just the lotto numbers between 2002 and now.
How could I do that?
0

Author Commented:
I've figured out how to extract all the numbers I need.
Now how can I genreate a guess based on the above criteria?
(items 2-5)?

My input text file looks like the following (all combinations on a single line):

04-06-07-16-35
04-16-18-24-36
04-17-28-32-35
02-09-16-19-21
03-14-29-30-36
07-13-15-20-29
02-15-26-28-31
06-15-19-24-2
12-24-25-28-31
0

Commented:
what algorithm you want to use on these numbers to guess it?
0

Commented:
Something like this should give you a rough idea depending on what you are trying to do..

--------------------------------------------
<?

\$data = "04-06-07-16-35
04-16-18-24-36
04-17-28-32-35
02-09-16-19-21
03-14-29-30-36
07-13-15-20-29
02-15-26-28-31
06-15-19-24-20
12-24-25-28-31";

// First thing doing is replace new lines with "-"

\$data = str_replace(array("\r\n","\n"),"-",\$data);

// Next explode it based on the -

\$numbers_called = explode("-",\$data);

// Loop through all numbers called and add them to a counter array

\$total_numbers=0;
\$my_counter = array();
foreach (\$numbers_called as \$key => \$value)
{
\$my_counter[\$value]++;
\$total_numbers++;
}
// sort the array numerically
ksort(\$my_counter);

echo("<b>Ordered numerically:</b><br><table border=1><TR><TH>NUMBER</TH><TH>Called</TH><TH>Percentage</TH></TR>");

foreach (\$my_counter as \$number => \$count)
{
echo("<TR><TD>".\$number."</TD><TD>".\$count."</TD><TD>".((\$total_numbers/100)*\$count)."%</TD></TR>");
}
echo("</table><br>");

// sort the array most called first
arsort(\$my_counter);

echo("<b>Ordered highest first:</b><br><table border=1><TR><TH>NUMBER</TH><TH>Called</TH><TH>Percentage</TH></TR>");

foreach (\$my_counter as \$number => \$count)
{
echo("<TR><TD>".\$number."</TD><TD>".\$count."</TD><TD>".((\$total_numbers/100)*\$count)."%</TD></TR>");
}
echo("</table><br>");

?>
--------------------------------------------

It will output 2 tables one being ordered numerical with count and percentages, the other being ordered most called first least called last.

Based on the second table you can decide which numbers you want to choose (either by which one is due or which one seems to hit most)
0

Commented:
woops screwed up the percentage calculation

instead of (\$total_numbers/100)*\$count it should be (100/\$total_numbers)*\$count
0

Commented:
Just for curiousities sake I ran the script on the real live data

End result for now:

Most commonly called numbers:
#  Called %
28 168     2.3952095808383%
47 164     2.3381807812946%
42 156     2.224123182207%
15 153     2.1813515825492%
48 151     2.1528371827773%
30 150     2.1385799828914%
18 149     2.1243227830054%
40 149     2.1243227830054%
08 149     2.1243227830054%
17 148     2.1100655831195%

Least called numbers:

#  Called %
53 54       0.76988879384089%
51 58       0.82691759338466%
50 71       1.0122611919019%
52 76       1.0835471913316%
33 110      1.5682919874537%
37 116      1.6538351867693%
23 121      1.725121186199%
05 122      1.739378386085%
32 125      1.7821499857428%
01 126      1.7964071856287%

Data file can be found at:
http://216.67.255.240/sb/testdata.txt

Results can be viewed at:
http://216.67.255.240/sb/test.php
0

Author Commented:
Very cool, I'll give this a run!
Btw, here's my shell script for getting the lottery numbers from the Florida Lottery Website:

#This could be done within PHP I'm sure -- I just don't know how to do it
#Also note that there is a typo in their PDF for one of the wins (they left out a dash between 19 and 22)
# This requires XPDF which has a pdftotext function
#!/bin/sh
# next line gets pages 15-18 which is all 2002-current winning numbers
pdftotext -layout -f 15 -l 18 -nopgbrk -raw -eol unix completenumbers.pdf
cat completenumbers.txt | grep -v [:alpha:] | grep -v '*' > numbers.txt
# next line prints only the winning numbers (removes the date field), fixes the typo and removes any blank lines
cat numbers.txt | awk '{print \$2}' | sed -e 's/03-14-1922-30/03-14-19-22-30/g' | grep -v ^\$ > \$\$.tmp
mv \$\$.tmp numbers.txt
rm -f completenumbers.pdf
rm -f completenumbers.txt
0

Author Commented:
For declariing \$data:

\$data = "04-06-07-16-35
04-16-18-24-36
04-17-28-32-35
02-09-16-19-21
03-14-29-30-36
07-13-15-20-29
02-15-26-28-31
06-15-19-24-20
12-24-25-28-31";

How can I read in the contents of that variable from a file instead?
0

Author Commented:
Ok, here's what I have so far:

\$fd = fopen ("pdf/numbers.txt", "r");
while (!feof (\$fd))
{
\$buffer = fgets(\$fd, 4096);
\$data[] = \$buffer;
}
fclose (\$fd);

// First thing doing is replace new lines with "-"
\$data = str_replace(array("\r\n","\n"),"-",\$data);

\$data = implode(\$data);

// Next explode it based on the -
\$numbers_called = explode("-",\$data);

// Loop through all numbers called and add them to a counter array
...snip (nothing changed below this line)

It seems to be working, except the output includes a blank line somewhere that is getting counted, eg:

Ordered numerically:
NUMBER      Called      Percentage
1        0.017283097131%
01          177      3.05910819219%
2           1             0.017283097131%

So the first row is a blank that is called one time.
0

Author Commented:
Also, now that that's done, how can I print something at the end like:

Your lotto numbers are (first 6 numbers ranked highest):
07      184      3.18008987211%
18      181      3.12824058071%
16      179      3.09367438645%
31      178      3.07639128932%
01      177      3.05910819219%
28      174      3.0072589008%

and then sort them numerically as they would appear on a lotto ticket:
1-7-16-18-28-31

Also:
This lotto is based on 1-53, do you think it would be useful to calculate the chance on a number being picked that has yet to win?
0

## Featured Post

• 6
• 3
Tackle projects and never again get stuck behind a technical roadblock.