jeudi 24 décembre 2020

C# Why get a zero number in random number

I'm trying to create an array list using random numbers. But sometimes I get a zero in results. I do not understand why.

I'm grateful if anyone can explain.

int[] number = new int[6];
Random rnd = new Random();
for (int i = 0; i < number.Length; i++)
{
   int random = rnd.Next(1, 26);
   if (!number.Contains(random))
   {
     number[i] = random;
   }
}
foreach (int nr in number)
{
  Console.Write("|" + nr + "|");
}
//results
|6||12||0||22||25||11|



Aucun commentaire:

Enregistrer un commentaire