Lottery Program for Texas Lottery Based on Most Frequent Numbers of the Past 20 Tickets

Published:

//
// Lotto6f.cs - program to forecast the lottery
//
using System;
using System.IO;

public class lotto6f
{
public const int max1 = 10000; // max data size
public const int nbits = 42; // number of bits
public const int isiz = 10; // number of reps
public int nnums = 6; // number of numbers
public int[,] data = new int[max1,11]; // data
public int[,] pred = new int[max1,11]; // predictions
public int[,] bitdata = new int[max1,42]; // bit rep. of dta
public double[] scores = new double[8]; // scores of lotto
public double[] scounts = new double[8]; // total number lto
public double[] scoresp = new double[8]; // total score
public int[,] fcastbin = new int[max1,42]; // forecasts
public int[] fcastbin2 = new int[42]; // forecast at end
public int[,] fcastdecimal = new int[max1,11]; // dec. forecasts
public int[] guesses = new int[11]; // guesses
public int[] actual = new int[11]; // actual lotto #s
public int count = 0; // # of tickets
public int[,] factors = new int[5,80]; // discriminant factors
public double[,] table1 = new double[42,2]; // table 1
public double[,] table2 = new double[42,4]; // table 2
public double[,] table3 = new double[42,8]; // table 3
public double qq1 = 0; // intermediate var
public double qq2 = 0; // intermediate var
public double qq3 = 0; // intermediate var
public int predq = 0; // intermediate var
public int kkk = 0; // special supress code
public int[,,] big60 = new int[max1,isiz,7]; // tabulation of final numbers
public int[] max6 = new int[6]; // tabulation of final numbers
public int[] numright2 = new int[7]; // tabulation of final numbers
public int[] datak = new int[7]; // tabulation of final numbers

//
// ProcessLine - to process one line of input of data
//
public void processline(string line1, int count)
{
Console.WriteLine(line1);
string[] strs = line1.Split(',');
int i1 = 0;
for (i1 = 0; i1 < 11; i1++)
{
try
{
data[count,i1] = int.Parse(strs[i1]);
}
catch
{
data[count,i1] = 0;
}
//Console.Write(data[count,i1]+",");
}
//Console.WriteLine();
}

//
// Loadbindata - to load the binary bits from the input file
//
public void loadbindata()
{
int i1 = 0;
int i2 = 0;
int i3 = 0;
int pos = 0;
int k = 0;
int dig = 0;
for (i1 = 0; i1 < count; i1++)
{
for (i2 = 0; i2 < 7; i2++)
{
k = data[i1,i2+4];
for (i3 = 5; i3 >= 0; i3--)
{
pos = i2*6 + i3;
dig = k % 2;
bitdata[i1,pos] = dig;
k = (int)k/2;
//Console.Write(k+" ");
}
//Console.WriteLine();
}
//Console.WriteLine();
}
for (i1 = 0; i1 < count; i1++)
{
//Console.Write((i1+1)+": ");
for (i2 = 0; i2 < 42; i2++)
{
//Console.Write(bitdata[i1,i2]+" ");
}
//Console.WriteLine();
}
}

//
// Loaddata - to load the input file
//
public void loaddata()
{
StreamReader sr = new StreamReader("data1.csv");
bool exitflag = false;
string line1 = "";
while (!exitflag)
{
try
{
line1 = sr.ReadLine();
if (line1[0] != ' ')
{
processline(line1,count);
count = count + 1;
}
else
{
exitflag = true;
}
}
catch
{
exitflag = true;
}
}
sr.Close();
loadbindata();
Console.WriteLine("# of Lines: "+count);
}

public void forecastlotto4()
{
int i1 = 0;
int i2 = 0;
int i3 = 0;
int i4 = 0;
int kk = 0;
int setup1 = 10;
int[] hist = new int[61];
int[] histn = new int[61];
int num = 0;
int tmp = 0;
Random rand = new Random();
for (i1 = setup1; i1 < (count); i1++)
{
Console.WriteLine("Ticket: "+i1);
Console.Write("Original: ");

for (i2 = 0; i2 < nnums+1; i2++)
{
num = 0;
for (i4 = 0; i4 < 6; i4++)
{
num = num*2 + bitdata[i1,i2*6 + i4];
}


Console.Write(num+",");

}

Console.WriteLine();
Console.Write("Prediction: ");

for (i3 = 0; i3 < 61; i3++)
{
hist[i3] = 0;
histn[i3] = i3;
}
for (i2 = i1 - setup1; i2 < i1; i2++)
{



for (i4 = 0; i4 < 6; i4++)
{
num = 0;
for (i3 = 0; i3 < 6; i3++)
{
num = num*2 + bitdata[i2,i4*6 + i3];
}

if ((num <= 60) && (num > 0))
{
hist[num] = hist[num] + 1;
}

}


for (i3 = 0; i3 < 61; i3++)
{
for (i4 = (i3 + 1); i4 < 61; i4++)
{
if (hist[i3] > hist[i4])
{
tmp = hist[i4];
hist[i4] = hist[i3];
hist[i3] = tmp;
tmp = histn[i4];
histn[i4] = histn[i3];
histn[i3] = tmp;
}
}
}
}

kk = 0;
for (i3 = 0; i3 < 61; i3++)
{
if ((histn[i3] > 0) && (kk < 6))
{
kk = kk + 1;
pred[i1+1,kk-1] = histn[i3];
Console.Write(pred[i1+1,kk-1]+",");
}
}
pred[i1+1,6] = rand.Next(1,6);
pred[i1+1,6] = 3;
Console.WriteLine(pred[i1+1,6]);






}


}

 


public void printresults2()
{
int i1 = 0;
int i2 = 0;
int i3 = 0;
int k = 0;
int found = 0;
//string strq = "";
//string strq1 = "";
try
{
for (i1 = 0; i1 < count; i1++)
{
k = 0;
Console.WriteLine("Ticket: "+i1);
Console.Write("Original: ");
for (i2 = 0; i2 < 7; i2++)
{
Console.Write(data[i1,i2+4]+",");
}
Console.WriteLine();
Console.Write("Forecast: ");
for (i2 = 0; i2 < 6; i2++)
{
Console.Write(pred[i1,i2]+",");
if (i1 < count)
{
found = 0;
for (i3 = 0; i3 < 6; i3++)
{
if (found == 0)
{
if (pred[i1,i2] == data[i1,i3+4])
{
k = k + 1;
found = 1;
}
}
}
}

}
Console.Write(pred[i1,6]+",");
if (pred[i1,6] == data[i1,10])
{
k = k + 1;
}
Console.WriteLine(" # Right: "+k);
scores[k] = scores[k] + 1;
//strq1 = Console.ReadLine();

}
}
catch
{
}


try
{
for (i1 = 0; i1 < 8; i1++)
{
scoresp[i1] = 100*scores[i1]/count;
Console.WriteLine("Score["+i1+"] = "+scoresp[i1]+" %");
}
//strq = Console.ReadLine();
}
catch
{
}
}


public void tabulate4b(int ii)
{
int i1 = 0;
int i2 = 0;
int i3 = 0;
int n = 0;
int tmp = 0;
int[] hist = new int[61];
int[] hist2 = new int[61];
//Console.WriteLine("Ticket: "+ii);
for (i3 = 0; i3 < 6; i3++)
{
//Console.Write(data[ii,i3+4]+",");
}
//Console.WriteLine();

for (i1 = 0; i1 < 61; i1++)
{
hist[i1] = 0;
hist2[i1] = i1;
}

for (i3 = 0; i3 < 6; i3++)
{
for (i2 = 0; i2 < isiz; i2++)
{
n = big60[ii,i2,i3];
hist[n] = hist[n] + 1;
}
//Console.Write(n+",");
}

for (i1 = 0; i1 < 61; i1++)
{
for (i2 = (i1 + 1); i2 < 61; i2++)
{
if (hist[i1] > hist[i2])
{
tmp = hist[i1];
hist[i1] = hist[i2];
hist[i2] = tmp;
tmp = hist2[i1];
hist2[i1] = hist2[i2];
hist2[i2] = tmp;
}
}
}

//Console.WriteLine();
//for (i1 = 0; i1 < 61; i1++)
//{
// Console.Write(hist2[i1]+",");
//}
//Console.WriteLine();
for (i1 = 0; i1 < 6; i1++)
{
datak[i1] = hist2[i1];
}

for (i1 = 0; i1 < 61; i1++)
{
hist[i1] = 0;
hist2[i1] = i1;
}

for (i3 = 6; i3 < 7; i3++)
{


for (i2 = 0; i2 < isiz; i2++)
{
n = big60[ii,i2,i3];
hist[n] = hist[n] + 1;
//Console.Write(n+",");
}

}
//Console.WriteLine();
for (i1 = 0; i1 < 61; i1++)
{
for (i2 = (i1 + 1); i2 < 61; i2++)
{
if (hist[i1] > hist[i2])
{
tmp = hist[i1];
hist[i1] = hist[i2];
hist[i2] = tmp;
tmp = hist2[i1];
hist2[i1] = hist2[i2];
hist2[i2] = tmp;
}
}
}

for (i1 = 6; i1 < 7; i1++)
{
datak[i1] = hist2[i1];
}
//Console.WriteLine("Datak:");
for (i1 = 0; i1 < 7; i1++)
{
//Console.Write(datak[i1]+",");
}
//Console.WriteLine();
}

public void bigsystem()
{

forecastlotto4();




}


public static void Main()
{
lotto6f l = new lotto6f();
bool exitflag = false;
int k = 0;
while (!exitflag)
{
Console.WriteLine("");
Console.WriteLine("Lotto6f.cs - Lottery Forecaster - (c) 2020 Leonard Gojer");
Console.WriteLine("1 - Load Data");
Console.WriteLine("2 - Forecast Lotto");
Console.WriteLine("3 - Print Results");
//Console.WriteLine("4 - Big System");
Console.WriteLine("0 - Exit");
Console.Write("> ");
k = int.Parse(Console.ReadLine());
switch (k)
{
case 1 : l.loaddata();
break;
case 2 : l.kkk = 0;
l.bigsystem();
break;
case 3 : l.kkk = 0;
l.printresults2();
break;
case 4 : l.bigsystem();
break;
case 0 : exitflag = true;
break;
}
}
}
}

Entry #2

Comments

This Blog entry currently has no comments.

Post a Comment

Please Log In

To use this feature you must be logged into your Lottery Post account.

Not a member yet?

If you don't yet have a Lottery Post account, it's simple and free to create one! Just tap the Register button and after a quick process you'll be part of our lottery community.

Register