+ Start a Discussion
charan@appcharan@app 

Developing Online Exam

I am trying to develop an online exam.

 

I was successful in keeping all the questions and writing class for them.

It works fine, but I need some questions which should be randomly picked from object.

Every time these questions should be different.

How can we achieve randomly ques from db?

 

Help me out at earliest.

NaishadhNaishadh

You can use math.random for fetching questions.

WesNolte__cWesNolte__c

Hey,

 

List<Question__c> questions = [SELECT id, name, body FROM Question__c];

LIst<Question__c> chosenQuestions = new List<Question__c>();

Integer listSize = questions.size();

 

for(Integer i = 0; i< 10; i++){

  Integer index = Math.random * listSize;

  chosenQuestions.add(questions[index]);

}

 

This isn't perfect, you could add the same question more than once for example, but it will get you started.

 

Wes

chowdary marellachowdary marella

iam using the following but getting repeated,can you please suggest?

 

Integer rand = Math.floor(Math.random()*14).intValue();


quess = new list<Questions__c>();
if(!i.contains(rand)){
quess = [SELECT Name FROM Questions__c limit 1 OFFSET :rand];
}
i.add(rand);
System.debug('@@@@Account@@@@@'+quess);

venkateshyadav1243venkateshyadav1243

Hi Charn am also developing the online exam using apex,visualforce.

 

can please tel me design and if u code can u please send me

 

 

Thanks,

venkatesh.

rajesh mummadirajesh mummadi

hello i also had a task for developing the online exam using apex,visualforce...please can any one send the source code for this.

 

 

thank you

rajesh(tcs)