I want to generate the random question paper. What I have tried till is this
public Set<Question> generateQuestionPaper(List<Question> list,
List<Criteria> template) {
// TODO Auto-generated method stub
Set<Question> s=new HashSet<Question>();
Random rand = new Random();
for(int i=0;i<template.size();i++)
{
int cnt=0;
for(int k=i;k<QuestionList.size();k++)
{
if(template.get(i).getComplexity()==QuestionList.get(k).getComplexity() && template.get(i).getCategory()==QuestionList.get(k).getCategory())
{
if(cnt<template.get(i).getNoOfQuestion())
{
s.add(QuestionList.get(k));
cnt++;
}
else
break;
}
}
}
return s;
}
The QuestionList holds the questions wheres as template list holds the template like
template.add(new Criteria(Category.GK,Complexity.Simple,2));
template.add(new Criteria(Category.GK,Complexity.Medium,1));
template.add(new Criteria(Category.GK,Complexity.Complex,1));
template.add(new Criteria(Category.Science,Complexity.Complex,1));
template.add(new Criteria(Category.History,Complexity.Medium,2));
template.add(new Criteria(Category.History,Complexity.Simple,2));
template.add(new Criteria(Category.Geography,Complexity.Medium,1));
what I am doing is just checking whether the category and complexity given in the template list is also there in questionList. It provides perfect output that is 2 GK questions which are simple, 1 GK question which is complex and so on as given in the template. But it is not generating random paper.
I know to generate random paper we have to use random function but i am not getting how to use it.
Database holds the values like queno,question,option1,option2,option3,correctans,complexity,category etc.
Please someone tell me how can I use random function to generate unique paper each time.
Thank you
Aucun commentaire:
Enregistrer un commentaire