class Pair {
    private double weight;
    private String value;

    Pair(double weight, String value) {
      this.weight = weight;
      this.value = requireNonNull(value);
    }
  }

  private final Collection<Pair> values = new ArrayList<>();
  private String lastvalue;

  public DiscreteGenerator() {
    lastvalue = null;
  }

  /**
   * Generate the next string in the distribution.
   */
  @Override
  public String nextValue() {<FILL_FUNCTION_BODY>

    double sum = 0;

    for (Pair p : values) {
      sum += p.weight;
    }

    double val = ThreadLocalRandom.current().nextDouble();

    for (Pair p : values) {
      double pw = p.weight / sum;
      if (val < pw) {
        return p.value;
      }

      val -= pw;
    }

    throw new AssertionError("oops. should not get here.");

  
<methods>public non-sealed void <init>() ,public final java.lang.String lastString() ,public abstract java.lang.String lastValue() ,public final java.lang.String nextString() ,public abstract java.lang.String nextValue() <variables>