lundi 9 mars 2015

How to select a number from random pool, then make so number can't be reselected

I'm basically trying to write a quiz as part of my classwork for computer programming, and I've ran into a spot of bother.


I want the questions to be selected from a random pool to discourage cheating, I could make it so that it randomly selects between the numbers of 1,8 but that can cause repeats in the questioning, which is something that I don't want.



Random random = new Random(); // We use this random object to choose random icons for the squares.

List<int> Assignments = new List<int>()
{

1,2,3,4,5,6,7,8

};

Random RandomlyChooseNumbers = new Random();

int AssignmentForQ1;
int AssignmentForQ2;
int AssignmentForQ3;
int AssignmentForQ4;
string CorrectAnswerA1;
string CorrectAnswerA2;
string CorrectAnswerA3;
string CorrectAnswerA4;
public double timePassed;
public int calculatedScore;
public int timeLeft;

public frmQuizOneHardMode()
{
InitializeComponent();

AssignQuestionToTextQ1();

}

private void AssignQuestionToTextQ1()
{
int randomNumber = RandomlyChooseNumbers.Next(Assignments.Count);

AssignmentForQ1 = Assignments[randomNumber];

Assignments.RemoveAt(randomNumber);

AssignmentForQ2 = Assignments[randomNumber];

Assignments.RemoveAt(randomNumber);

AssignmentForQ3 = Assignments[randomNumber];

Assignments.RemoveAt(randomNumber);

AssignmentForQ4 = Assignments[randomNumber];

Assignments.RemoveAt(randomNumber);
}


But for some reason, the numbers are always the same, which means that AssignmentForQ1,Q2,Q3 and Q4 all show the exact same question, I have literally no idea what's going wrong here, can someone please help?





Aucun commentaire:

Enregistrer un commentaire