如何避免重复的随机问题 [英] How to avoid duplicate random questions

查看:91
本文介绍了如何避免重复的随机问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个应用程序,即FE考试程序,用户将参加由随机问题组成的测试.由于存在一些重复的问题,我在显示问题时遇到了麻烦.我将使用哪种方法或有关此过程.请帮助我.谢谢! :)


非常感谢,
丽亚·梅(Rhea May):-D



[添加]
谢谢您的想法!您能提供与该方法有关的一些代码来避免重复问题吗?我只想澄清一下.
[/add]

I am making an application which is the FE Exam program wherein the user will take the test that compose of random questions.I''m having trouble in displaying the questions because there are some duplicates of questions.What method will I use or process in regards to this.Please help me.Thanks! :)


Much appreciated,
Rhea May :-D



[added]
Thanks for your idea!Can you give some codes pertaining the method to avoid the duplicates of questions?I just want to clarify it.
[/added]

推荐答案

获取所有问题的列表.然后随机将它们弄乱.您可以通过选择随机索引并将该问题复制到新列表中来完成此操作.然后,将第一个列表中的列表项移动到刚选择的问题的位置.然后将第一个列表的大小减小1.重复此过程,直到第一个列表为空.您的第二个列表将以随机顺序排列,并且列表中的每个项目都是唯一的.

那是您可以执行此操作的许多方法之一(例如,您可以使用带有问题哈希的哈希表以确保没有重复项).
Get a list of all the questions. Then randomly jumble them. You can do this by selecting a random index and copy that question to a new list. Then, move the list item in the first list to the position of the question you just selected. Then reduce the size of the first list by 1. Repeat this procedure until your first list is empty. Your second list will be in a random order and each item in the list will be unique.

That is one of many ways you could do this (e.g., you could use a hash table with a hash of the questions to ensure there are no duplicates).


您可以阅读以下内容:从卡组中随机抽取5张卡" .
基本上,它显示了如何随机抽取项目来避免重复(我知道它是C,但评论很多).
:)
You may read my: "Random extraction of 5 cards from a deck".
Basically it shows how random extract items avoiding duplications (It is C, I know, but is heavy commented).
:)


您可以随机选择它们并将其添加到HashTable.

HashTable集合不允许重复的键,因此您可以继续检索随机选择的问题,直到您的哈希表包含所需数目的问题为止.

(我假设您的问题对象具有某种可以用作键的唯一标识符).
You could randomly select them and add them to a HashTable.

The HashTable collection don''t allow duplicate keys, so you could just keep retrieving randomly selected questions until your hash table contains the desired number of questions.

(I''m assuming your question object has some sort of unique identifier you can use as a key).


这篇关于如何避免重复的随机问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆