i have problems with an array, i want get the values of positions, but without repeating the positions(with the next.random the values are repeat, but i need once get the position), i post my code for you see them. i hope you can help me.
int d = 0;
for (int i = 0; i < caminohormiga.Length; i++)
{
int start2 = random.Next(0, caminohormiga.Length);
d = caminohormiga[start2];
MatrizAux[i] = d;
if (caminohormiga[i] == 0)
{
Console.Write("Repetido");
}
Console.Write(caminohormiga[i] + ", ");
}
You need to make an array of indexes, fill it with numbers zero through length minus one, make a random shuffle, and go through the shuffled array to pick the index of the original array.
You can use Fisher-Yates Shuffle algorithm to re-arrange the indexes.