// Primitive Power Ball C# Samples Generator - Global Lotomania in action:)
// David Taran January 11, 2016
// For PowerBall as a answer type: 5, 69, 1, 26, -1, 10...
using System;
namespace Loto5p1
{
class Program
{
static void Main(string[] args)
{
int iRegularBallsCount,
iRegularBallsMaxNumber,
iPowerBallsCount,
iPowerBallsMaxNumber,
iGenerationInitialNumber,
iDrawingsNumber;
do
{
Console.Write("Ener Regular Balls Count: ");
iRegularBallsCount = Int32.Parse(Console.ReadLine());
}
while (0 > iRegularBallsCount);
do
{
Console.Write("Ener Regular Balls Max Number: ");
iRegularBallsMaxNumber = Int32.Parse(Console.ReadLine());
}
while (iRegularBallsCount >= iRegularBallsMaxNumber);
do
{
Console.Write("Ener Power Balls Count: ");
iPowerBallsCount = Int32.Parse(Console.ReadLine());
}
while (0 > iPowerBallsCount);
do
{
Console.Write("Ener Power Balls Max Number: ");
iPowerBallsMaxNumber = Int32.Parse(Console.ReadLine());
}
while (iPowerBallsCount >= iPowerBallsMaxNumber);
Console.Write("Ener Your Generation Initial Number (-1 for std gen): ");
iGenerationInitialNumber = Int32.Parse(Console.ReadLine());
Console.Write("Ener Drawings Number: ");
iDrawingsNumber = Int32.Parse(Console.ReadLine());
Loto loto = new Loto(iRegularBallsCount, iRegularBallsMaxNumber,
iPowerBallsCount, iPowerBallsMaxNumber,
iGenerationInitialNumber);
for (int i = 0; i < iDrawingsNumber; i++)
{
Console.WriteLine("\n"+loto.GetOneDrawing());
}
Console.ReadLine();
}
}
class Loto
{
private
int iRegularSamplesCount,
iRegularBallsCount,
iPowerSamplesCount,
iPowerBallsCount,
iGenerationInitialNumber;
RandomSample rdsBall = new RandomSample(),
rdsPower= new RandomSample();
int[] iRegular;
int[] iPower;
public
Loto(int iRegularSamplesCount_, int iRegularBallsCount_,
int iPowerSamplesCount_, int iPowerBallsCount_,
int iGenerationInitialNumber_)
{
iRegularSamplesCount = iRegularSamplesCount_;
iRegularBallsCount = iRegularBallsCount_;
iPowerSamplesCount = iPowerSamplesCount_;
iPowerBallsCount = iPowerBallsCount_;
iGenerationInitialNumber = iGenerationInitialNumber_;
iRegular = new int[iRegularSamplesCount];
iPower = new int[iPowerSamplesCount];
rdsBall.Init(iRegularSamplesCount, iRegularBallsCount, iGenerationInitialNumber);
rdsPower.Init(iPowerSamplesCount, iPowerBallsCount, iGenerationInitialNumber);
}
public
string GetOneDrawing()
{
rdsBall.GetSamplesSet(iRegular);
rdsPower.GetSamplesSet(iPower);
string str = "";
foreach (int i in iRegular)
str += String.Format(" {0:d2}",i);
foreach (int i in iPower)
str += String.Format(" {0:d2}", i);
return str;
}
}
class RandomSample
{
private
int iSamplesCount,
iMaxSampleValue;
bool bIsInit;
Random rnd;
double[] rnd2intDelta;
int[] iAllValidNumbers;
int[] iSamplesSet;
public RandomSample()
{
bIsInit = false;
}
public
void Init(int iSamplesCount_, int iMaxSampleValue_, int iRndInitValue)
{
if (0 > iSamplesCount_ || 0 > iMaxSampleValue_
|| iSamplesCount_ >= iMaxSampleValue_)
return;
iSamplesCount = iSamplesCount_;
iMaxSampleValue = iMaxSampleValue_;
if (-1 == iRndInitValue)
rnd = new Random();
else
rnd = new Random(iRndInitValue);
rnd2intDelta = new double[iSamplesCount];
int i, k;
for (i=0, k=iMaxSampleValue; i<iSamplesCount; i++,k--)
rnd2intDelta[i] = 1e0/(double)k;
iAllValidNumbers = new int[iMaxSampleValue];
iSamplesSet = new int[iSamplesCount];
bIsInit = true;
}
public
bool GetSamplesSet(int [] iSample)
{
if (!bIsInit)
return false;
int i, j, k;
double drnd;
for (i = 0; i < iMaxSampleValue; )
iAllValidNumbers[i] = ++i;
for (j = 0, k = iMaxSampleValue; j < iSamplesCount; j++,k--)
{
drnd = rnd.NextDouble();
i = (int)(drnd / rnd2intDelta[j]);
if (i == k)
i--;
iSamplesSet[j] = iAllValidNumbers[i];
if (i != k-1)
iAllValidNumbers[i] = iAllValidNumbers[k-1];
}
Array.Sort(iSamplesSet);
iSamplesSet.CopyTo(iSample, 0);
return true;
}
}
}
David_66 0 Newbie Poster
tinstaafl 1,176 Posting Maven
ddanbe commented: Nice advice +15
David_66 0 Newbie Poster
tinstaafl 1,176 Posting Maven
JOSheaIV 119 C# Addict
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.