I have a method that have to compare an integer with an Arraylist and if the number on the integer is on the arraylist, I recieve a false. If the integer number is not on the arraylist I recieve a true.
I need this, because I'm making a quiz game that have some questions on a BBDD and I can't show the same question twice. Also this questions are in three categories: E, I and A. I have to show five E questions, then five I questions and then five A questions.
So I have to show questions without repeat them, and also 5 of each category. I make this methods but I don't know why it repeats some questions.
The only thing works correctly is the category questions. I have always 5 E questions, then 5 I questions and at least 5 A questions.
The method that told me if the questions is on the ArrayList:
private boolean checkRandom()
{
    for(int i = 0; i < listRandom.size(); i++)
    {
        if(questionPosition == listRandom.get(i))
        {
            return false;
        }
    }
    return true;
}
I also try with "equals", but I have the same result.
The method that check if the question is in the correct category and is not showed before:
private void loadPhase() {
    if (numQuestion < 15)
    {
        r = new Random();
        questionPosition = r.nextInt(listQuestions.size());
        if(numQuestion < 5)
        {
            while(!listPhase.get(questionPosition).equals("E") && (!listPhase.get(questionPosition).equals("E")|| !checkRandom()))
            {
                r = new Random();
                questionPosition = r.nextInt(listQuestions.size());
            }
        }
        else if(numQuestion > 4 && numQuestion < 10)
        {
            while(!listPhase.get(questionPosition).equals("I") && (!listPhase.get(questionPosition).equals("I")|| !checkRandom()))
            {
                r = new Random();
                questionPosition = r.nextInt(listQuestions.size());
            }
        }
        else if(numQuestion > 9)
        {
            while(!listPhase.get(questionPosition).equals("A") && (!listPhase.get(questionPosition).equals("A")|| !checkRandom()))
            {
                r = new Random();
                questionPosition = r.nextInt(listQuestions.size());
            }
        }
        listRandom.add(questionPosition);
        header4questions.setText(listQuestions.get(questionPosition));
        answer1.setText(listAnswers.get(questionPosition * 4));
        answer2.setText(listAnswers.get((questionPosition * 4) + 1));
        answer3.setText(listAnswers.get((questionPosition * 4) + 2));
        answer4.setText(listAnswers.get((questionPosition * 4) + 3));
        numQuestion++;
    }
    else {
        Toast.makeText(getApplicationContext(), "You have finished the quiz!", Toast.LENGTH_SHORT).show();
        uploadPoints();
    }
}
So, what I have is all the questions on the correct category, but it repeat the questions and I don't know why.
Can anyone help me?
Thanks!
 
     
    