For a mini project I am making a quiz program My current (relavant) code is as follows:
static Random _r = new Random();
static int Quiz()
{
string[,] QAndA = {
{"What is the capital of France", "Paris"},
{"What is the capital of Spain", "Madrid"},
...
{"What is the captial of Russia", "Moscow"},
{"What is the capital of Ukraine", "Kiev"},
};
for (int i = 0; i < NUM_QUESTIONS; i++)
{
int num = _r.Next(QAndA.GetLength(0) / 2);
Question(QAndA[num, 0], QAndA[num, 1]);
}
}
Now, the obvious problem with this is that the random numbers can be repeated, meaning that questions can be repeated.
Now, my teacher (yes, this is a school thing) told me to look for shuffling algorithms, but I have failed to find any that work for multidimensional arrays like i have used.
I am a fairly new c# programmer, but I have experience with c++ and the program is a commandline program (at the moment :) ), if that matters/helps
So, the question is, what's the best way of reordering/shuffling the multidimensional array to be in a random order?
Questionclass with aQuestionand anAnswerproperty.