/** maintain a list of words, from which one can be selected randomly
 */
import java.util.Random;
public class WordList {

  // list of words, delimited on the right by newlines
  private String words;

  // a random number generator
  private static Random random= new Random();
  
  // constructor: create a wordlist equal to list
  // precondition: list must be a string comprised of
  // 4-letter words, each followed by one space.
  public WordList(String list) {
    words= list;
  }

  /** select a word from our list words
   */
  public String select() {
    int wordStart;
    // wordStart will be a random number in the range 0 .. 5n-1
    // where n is the number of words in our list
    wordStart= random.nextInt((words.length()/5)) * 5;
    return words.substring(wordStart,wordStart + 4);
  }
}



