mardi 1 décembre 2020

How to genereate random numbers from a range when button is used but the numbers cannot repeate

I am creating a quiz and im using a random number from a range of 1 - 20 numbers ( Primary Keys)

Random r = new Random();
int rInt = r.Next(1, 9);

The numbers(primary keys) and then used for a query to select 5 random number but the problem is that I am getting repeated questions because the numbers repeat

 string SQL = "SELECT QuestionText,CorrectAnswer,WrongAnswer1,WrongAnswer2,WrongAnswer3 FROM Question Where QuestionID = " + rInt;

I have tried some methods to fix it but its not working and running out of ideas , anyone have any suggestions?




Aucun commentaire:

Enregistrer un commentaire