View Single Post
  #7   Spotlight this post!  
Unread 31-07-2012, 16:39
quinxorin quinxorin is offline
Mentor now :(
AKA: Ian Pudney
FRC #0862 (Lightning Robotics)
Team Role: Mentor
 
Join Date: Jan 2009
Rookie Year: 2009
Location: Lightning Robotics
Posts: 148
quinxorin will become famous soon enough
Re: Replacing duplicates in a randomly generated array

Another possible technique, and probably the fastest executing, would be to generate an array of all possible questions (say 1-100), randomize it, and select the top however many items (say, 10). This would give you no duplicates and would not have time complexity issues. A logical way to think of this is randomly generating a number, where the range of numbers possibly generated is only those which have not yet been generated.

This is how a trivia game on our website works.
__________________
"Sed res docuit id verum esse, quod in carminibus Appius ait, fabrum esse suae quemque fortunae."
- Every man is the architect of his own fortune.