#1
12.03.2015 um 09:24 UhrHab es runtergekürzt auf:
C#-Code
class Program
{
static int digits = 6;
static void Main(string[] args)
{
Random zufall = new Random();
int[] zahlen = new int[digits];
List<int> ranZahlen = new List<int>();
while (ranZahlen.Count != digits)
{
int z = ((zufall.Next(1, 50) + zufall.Next(1, 50)) % 49) + 1;
if (!ranZahlen.Contains(z)) ranZahlen.Add(z);
}
Lotto loto = new Lotto(ranZahlen.ToArray());
loto.run();
for (int i = 0; i <= digits; i++)
{
Console.WriteLine(i + " Richtige: " + ((double)loto.richtigeZahlen[i] / (double)loto.richtigeZahlen.Sum() * 100f).ToString("00.000000") + "%");
}
Console.ReadKey();
}
}
class Lotto
{
private int[] zahlen;
private Random zufall = new Random();
public int[] richtigeZahlen;
public Lotto(int[] zahlen)
{
this.zahlen = zahlen;
}
public void run()
{
richtigeZahlen = new int[zahlen.Length+1];
for (int richtig = 0; richtig != zahlen.Length; )
{
richtig = getGameNumbers().Where(x => zahlen.Contains(x)).Count();
richtigeZahlen[richtig]++;
}
Console.WriteLine("Finished");
}
private int[] getGameNumbers()
{
List<int> ranZahlen = new List<int>();
while (ranZahlen.Count != zahlen.Length)
{
int z = zufall.Next(1, 50);
if (!ranZahlen.Contains(z)) ranZahlen.Add(z);
}
return ranZahlen.ToArray();
}
}
