Exemplo n.º 1
0
  public String choose() {
    int ran = Math.abs(Analysis.random.nextInt() % nEntries);
    Iterator iter = completions.keySet().iterator();
    int sum = 0;

    while (iter.hasNext()) {
      String key = (String) iter.next();
      WordEntry we = (WordEntry) completions.get(key);
      if (we == null) throw new NullPointerException();
      sum += we.getnEntries();
      if (ran <= sum) return we.word;
    }
    throw new NullPointerException("Cannot get here");
  }