I am making a C# script in visual studio for windows forms.
I need to get non duplicated numbers and that is what I have tried in that script, what happens is that when i compile the project, I get this random numbers, but sometimes, those numbers are duplicated, so I would like if you tell me which mistake I have made, or even if the mistake is in that piece of code.
I need to store this random numbers from 1 to 75 to say if these 75 created random numbers, compared with a table with some numbers that I already have are equal.
for (int i = 0; i < 76; i++)
{
auxiliar = random.Next(1, 75);
bool continuar = false;
while (!continuar)
{
for (int j = 0; j <= contador; j++)
{
if (auxiliar.ToString() == totalBalotas[j])
{
continuar = true;
j = contador;
}
}
if (continuar)
{
auxiliar = random.Next(1, 75);
devuelve = auxiliar.ToString();
continuar = false;
estaContando = true;
return devuelve;
}
else
{
continuar = true;
totalBalotas[contador] = auxiliar.ToString();
devuelve = auxiliar.ToString();
contador++;
estaContando = true;
return devuelve;
}
}
}
estaContando = true;
return devuelve;
}
This is the code.
https://i.stack.imgur.com/D7wqk.png