Get a random string from a table, but not more than once
<p>I'm trying to figure out how i can get random strings out of a table, including 10 words. I'm creating the game hangman, but i don't want one word twice. The game shall go on until 5 words are picked.</p>

<p>Are there any good solutions? This is the randomizing method for my table as it is now.</p>

<pre><code>private String wordList[] = { "String1", "String2", ..... }
public void getRandomWord(){
    Random generator = new Random();
    int r = generator.nextInt(9);
    activeWord = wordList[r];
}
</code></pre>

<p>I tried getting this to work, but no luck:</p>

<pre><code>ArrayList&lt;String&gt; usedWords= new ArrayList&lt;String&gt;();
public void getRandomWord(){
    Random generator = new Random();
    int r = generator.nextInt(9);
    if(addWord(wordList[r])){
        activeWord= wordList[r];
    }
}

private boolean addWord(String word) {
    for(String v : usedWords){
        if(!v.equals(word)){
            usedWords.add(word);
            return true;
        }
        else{
            getRandomWord();
        }
    }
    return false;   
}
</code></pre>

<p>I think i've made an iteration, but i'm guessing thats not nessasary.</p>

<p>I've been thinking about having a string table with boolean value. So if the value of the word is true, ill grab it, if its not, ill keep going until i find a word.</p>

<p>I might use a while loop for that?</p>
