Android random activites without repetition

后端 未结 2 1671
谎友^
谎友^ 2021-01-28 04:08

I am developing a quiz game, where I have to get random activities on answering the questions as to avoid the questions in same order. I have fixed this by using switch

相关标签:
2条回答
  • 2021-01-28 05:14

    Follow these steps:

    1. Create an ArrayList (or a List simply) and add all your Questions to it. Remember this only holds the questions for shuffling. Do not use it for any other purpose.
    2. Then do a shuffle using Collections.shuffle(question).
    3. Ask the question on top (question.get(0));
    4. After this has been answered remove it from the List. This will ensure it is never shown again.
    5. Repeat steps 2 - 5 till your List size is greater than zero.

    Let me know if it is unclear.

    0 讨论(0)
  • 2021-01-28 05:14

    use

    ArrayList<Integer> number = new ArrayList<Integer>();
    for (int i = 1; i <= 10; ++i) number.add(i);
    Collections.shuffle(number);
    
    0 讨论(0)
提交回复
热议问题