I'm learning to program, i need my quiz random questions not to be repeated. Java - Android Studio
##my code:
quizModalArrayList = new ArrayList<>();
random = new Random();
getQuizQuestion(quizModalArrayList);
currentPos = random.nextInt(quizModalArrayList.size());
private void getQuizQuestion(ArrayList<QuizModal> quizModalArrayList) {
quizModalArrayList.add(new QuizModal(R.drawable.prolinfocitos, "b", "b", "c", "dd","b"));
quizModalArrayList.add(new QuizModal(R.drawable.prolinfocitos, "b", "b", "c", "dd","b"));
quizModal there are more lines of code, but I believe they are unrelated to the problem.
any help? Thanks
CodePudding user response:
You have to rethink your approach. The easiest solution: you define the complete random order upfront. Meaning: you first load all your questions into your base list, in whatever order. Then you create a copy of that list, and shuffle that copy (using that built in function: Collections.shuffle(List). And that shuffled list copy is what your user gets to see. And then you just iterate that list bottom to top.