0

Hi guys i'm developing a tests generator app using asp mvc. And i need to select random questions based on some conditions randomly using some test template. Each question has a domain and a difficulty. A test template has the following structure.

Formula

NoOfQuestions
QuestionDomain
NoOfQuestionsPerDomain
QuestionDifficulty
NoOfQuestionsPerDifficulty

NoOfQuestions = NoOfQuestionsPerDomain + NoOfQuestionsPerDificulty.

Code

List<Question> questions = ctx.Questions.Where(q => Domains.Contains(q.Domain) && difficulties.Contains(q.Difficulty)).ToList();

My question is how can i choose a random question set based on the properties above ? thanks!

SamGhatak
  • 1,487
  • 1
  • 16
  • 27
Gabriel Burciu
  • 123
  • 2
  • 6
  • Well i got the all filtered question set based on domain and difficulty, now i just need to select random questions based on NumberOfQuestion/Domain and NumberOfQuestion/Difficulty from the filtered set. – Gabriel Burciu May 24 '16 at 10:11
  • Can we have the code her instead of the formula? – SamGhatak May 24 '16 at 10:12
  • To get a random list create a List>. Your current filtered list is the object. Assign a random number (the int in the keypair) to each keypair. the sort list by the random number. Then take from top of list the NoOfQuestions you need. This method insures you only take each question one time. – jdweng May 24 '16 at 10:14
  • List questions = ctx.Questions.Where(q => Domains.Contains(q.Domain) && difficulties.Contains(q.Difficulty)) .ToList(); – Gabriel Burciu May 24 '16 at 10:14
  • you should update your question with the code you tried to made it more readable, rather than writing code in comments. – Mukesh Modhvadiya May 24 '16 at 10:36

0 Answers0