6
I have a method that its function is to return 25 random numbers on a list:
static List<int> criarList()
{
List<int> lista = new List<int>();
for (int i = 0; i < 25; i++)
{
lista.Add(new Random().Next(0, 100));
}
return lista;
}
But for some reason, it only returns the same numbers, that is, all the same:
Why is this happening? How to fix?
The class
Random
appears to generate a sequence of numbers that meet certain statistical randomness requirements. The sequence is generated from a standard seed, based on time. Wouldn’t it be the problem that all instances of the class are using the same seed and thus generating the same sequence? Why don’t you call the methodNext
of the same instance 25 times?– Woss