For school I need to make a project in C# that will ask 20 questions at random.
I have a textfile that contains the questions with the answers.
With some code we put the questions in a array. Now we can generate an number from 0 to 19 (20 questions). But each question need to appear 1 time and 1 time only.
We can't do the first at random and the next in order. Every question needs to be at random.
My code (in Dutch):
public int randomVraagMaker()
{
int num;
Random randNum = new Random();
num = randNum.Next(0, 19);
for (int i = 0; i < lijst.Count; i++)
{
if (num == lijst[i])
{
num = randNum.Next(0, 19);
}
else
lijst.Add(num);
}
vraag = num * 7;
return vraag;