As long as I have the readkey in the code the end result is 7 different random loops (foreach). When I remove readkey I mostly get 7 identical numbers (foreach).
That led me to start experimenting with Task.Delay but it seems to make no difference. I thought it might be a timing problem as intemittently the first of the 7 random numbers would be different from the last 6.
I want the code to work in one sweep without me having to press a key. My apology if the format in this post is dodgy. I have bad experince of pressing ENTER in this input window.
int[] tray = new int[7];
for (int i = 0; i < tray.Length; i++)
{
Random rnd = new Random();
int randomNumber = rnd.Next(1, 26);
//Task.Delay(9000);
tray[i] = randomNumber;
Console.WriteLine("randomNumber {0} is {1} ENTER ", i + 1, tray[i]);
//Task.Delay(9000);
Console.ReadKey();
}
foreach (var number in tray)
{
Console.WriteLine(number);
}
Aucun commentaire:
Enregistrer un commentaire