简体   繁体   English

如何让我的随机问题不再重复?

[英]How to make my random questions not repeat?

I'm learning to program, i need my quiz random questions not to be repeated.我正在学习编程,我需要我的测验随机问题不要重复。 Java - Android Studio Java - Android 工作室

##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. quizModal有更多的代码行,但我相信它们与问题无关。

any help?有什么帮助吗? Thanks谢谢

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.然后您创建该列表的副本,并将该副本打乱(使用内置的function : Collections.shuffle(List) 。打乱的列表副本是您的用户可以看到的。然后您只需从下到上迭代该列表.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM