Click here to Skip to main content
15,887,353 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
I need this code in c#
I need the designing of quiz test .
in which i can retrive the questions from DataBase where total 500 questions are present, but i want to retrive 60 question out of 500 randomly each time & also new questions display each time

What I have tried:

My Questions table contains the following columns:
qid mean question id
sid mean subject id
question
ans1 means option1
ans2 means option2
ans3 means option3
ans4 means option4
cans means correct ans
Posted
Updated 21-Mar-16 9:22am
Comments
ZurdoDev 21-Mar-16 15:07pm    
What is your question?
RickZeeland 21-Mar-16 15:23pm    
Does it have to be a database ? as you only have 500 questions you could easily do without a database and use an .xml file (editable in Excel for example).

1 solution

That's complex, because there are two conflicting constraints here: randomness and lack of repetition.
You can do randomness from a DB:
SQL
SELECT TOP 60 * FROM MyTable
ORDER BY NEWID()

It's the lack of repetition that's a problem.
The way I'd do it is to keep a usage count with each row, and UPDATE it from your C# each time you display a question. Then use the SELECT to ORDER by the usage count and then NEWID:
C#
SELECT TOP 60 * FROM MyTable
ORDER BY UseCount, NEWID()
That way, the oldest question are returned, in a random order.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900