My WinForms lottery program asks for 8 numbers. First 7 of them are lottery picks, the last one represents number of spins. After clicking on the "Start Button", user can see how many times did he score 5, 6 or 7 matches. The problem lies in these results, they are very inconsistent. I can get for example 0-5s, 46223-6s and 0-7s in 999999 spins after 1st try, 2nd try: 12512-5s, 5002-6s, 0-7s and 3rd try i got 3 zeros(0 0 0). I went through the code with Debugger(working in Visual Studio) and there should no longer be any problems with doubles. To be honest i don't know what is wrong.
Here comes the code:
for (int n = 0; n < spins; n++)
{
List<string> rand = func.randomizer();
rand = func.compare(numb, rand);
if (rand.Count == 2) five++;
if (rand.Count == 1) six++;
if (rand.Count == 0) seven++;
{
and randomizer and compare:
public List<string> randomizer()
{
ArrayList randNumb = new ArrayList();
Random generator = new Random();
int randomNumb;
List<string> rand = new List<string>();
for (int i = 0; i < 7; i++)
{
do
{
randomNumb = generator.Next(1, 36);
}while (randNumb.Contains(randomNumb));
randNumb.Add(randomNumb);
rand.Add(randomNumb.ToString());
}
return rand;
}
public List<string> compare(List<string> numb, List<string> rand)
{
rand.Remove(numb[0]);
rand.Remove(numb[1]);
rand.Remove(numb[2]);
rand.Remove(numb[3]);
rand.Remove(numb[4]);
rand.Remove(numb[5]);
rand.Remove(numb[6]);
return rand;
}
Thanks for help. /bow