|
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.
|