Breaking News
Loading...

Logic : Getting Random Numbers and Random Questions using Array List Class

8:23 PM

getting Random Numbers :
=======================
public ArrayList getRandomList() {
Random rand = new Random();
ArrayList alist = new ArrayList();
while (alist.size() < 5) {
int v = rand.nextInt(5);
if (!alist.contains(v)) {
alist.add(v);
}
}
return alist;
}








Getting Random Questions from ArrayList :
-----------------------------------




public ArrayList getQuestions(int level, ArrayList listObj){
ArrayList listObj2=new ArrayList();
Random r=new Random();
while(listObj2.size()<=20)
{
int r1=r.nextInt(listObj.size());
ModuleQuesBean mq=listObj.get(r1);
int lid=Integer.parseInt(mq.getLid());
if(lid==level)
{
if(!listObj2.contains(mq));
{
listObj2.add(mq);
}
}
}
for(int i=0;i<10;i++)
{
Log.w(" array list values ",listObj2.get(i).getQuestionid()+"");
}
return listObj2;
}

0 komentar:

Post a Comment

 
Toggle Footer