Click here to Skip to main content
15,890,897 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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]
Posted
Updated 17-Feb-10 8:37am
v2

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).
 
Share this answer
 
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).
:)
 
Share this answer
 
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).
 
Share this answer
 
v2
Do you have some codes using java technology in regards to the method of avoiding the duplicates of random questions instead of turbo C?Because I'm using java language.I need your help.Thanks!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900