Not Repeating Items in a List
Submitted by rosenz on Mon, 04/14/2008 - 15:49.
Markus Wrote:
I am making a rather simple word game which reads in words from an XML-file (randomized). What I want to do is having a randomized order but sometime keeping track of which words has already been used in the game, so that I dont risk that a word will appear twice in the game. Do you have any solution for this?
This is a pretty common task. If your list is shuffled into a random order, though, then you don't have to worry about it. For instance, if you have 100 words, and then put them in a random order, and then take one word from the list at a time, then you should never end up with the same word twice as you are removing words from the list as you go. The key is to shuffle the array or words, and then remove them as you use them. For an example, see the section "Randomizing the Questions" in chapter 10 of the book.
»
- Flash Game University Blog
- Login or register to post comments
Copyright Gary Rosenzweig
