I'm doing simple Xamarin.Forms puzzle game and i need to have 9 puzzles with diffrent random values. I tried to check it with some loops, but it's still not working.
Random r = new Random();
Label[] puzzles = { puz1, puz2, puz3, puz4, puz5, puz6, puz7, puz8, puz9 };
string[] used = new string[9];
for (int i = 0; i < puzzles.Length; i++)
{
if (i > 0)
{
for (int x = 1; x < used.Length; x++)
{
do
{
puzzles[i].Text = Puzzles.puz[r.Next(0, 8)];
used[x] = puzzles[i].Text;
}
while (used[x - 1] == used[x]);
}
}
else
{
puzzles[i].Text = Puzzles.puz[r.Next(0, 8)];
used[0] = puzzles[i].Text;
}
}
And Puzzles.cs class
class Puzzles
{
public static string[] puz = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
}
How can I check that new generated puzzle hasn't the same value that puzzles generated previously?