Im trying to write a c# programme that will generate a random number, check if this number is in my array, if it is, repeat generate number step, else insert this number into slot [i] of my array.
Here is my code so far - Any help would be greatly appreciated! :)
int check=0, lottoCheck;
Random rand = new Random();
int[] lotto = new int[6];
//Need while loop wrapped around this - parameters something like -while x < filled slot lotto arrays. cant think of how to write this :(
for (int i = 0; i < lotto.Length; i++) // this will limit the loop to only 6 - must change!
{
check = rand.Next(1, 41);
Console.WriteLine("Random number to be checked is -> "+check);
if (lotto.Contains(check))
{
lotto[i] = check;
}
Console.WriteLine("slot " + i + " contains " + check);
}