Skip to content Skip to sidebar Skip to footer

Prevent Repeat In Shuffle Mode

How do I random out my already asked question (so that it doesn't repeat) in a quiz? What's the best possible way to achieve this without crashing the app? Problem: I wanted to kee

Solution 1:

Tip: Maintain an ArrayList

  1. Create an ArrayList.
  2. Add the indexes of the questions. eg: 1,2,3,4.....n in list.
  3. Generate a random number within the range of size of List.
  4. Display the question corresponding to the random number generated(preferably the index of the question number).
  5. After displaying the question remove that item from the list.
  6. As you delete the item from the list, the list gets updated and all the elements after the deleted elements move up by one position and size of the list gets updated (reduced by 1).
  7. Again generate a random number within the range of size of the list and repeat the process.

    list.get(random_number); will give you the index of the number stored in that position so that you can display your position accordingly.

Let me know if any point is not clear or ambiguous. I'll update it.

Post a Comment for "Prevent Repeat In Shuffle Mode"