class HistogramGenerator extends NumberGenerator {

  private final long blockSize;
  private final long[] buckets;
  private long area;
  private long weightedArea = 0;
  private double meanSize = 0;

  public HistogramGenerator(String histogramfile) throws IOException {
    try (BufferedReader in = new BufferedReader(new FileReader(histogramfile))) {
      String str;
      String[] line;

      ArrayList<Integer> a = new ArrayList<>();

      str = in.readLine();
      if (str == null) {
        throw new IOException("Empty input file!\n");
      }
      line = str.split("\t");
      if (line[0].compareTo("BlockSize") != 0) {
        throw new IOException("First line of histogram is not the BlockSize!\n");
      }
      blockSize = Integer.parseInt(line[1]);

      while ((str = in.readLine()) != null) {
        // [0] is the bucket, [1] is the value
        line = str.split("\t");

        a.add(Integer.parseInt(line[0]), Integer.parseInt(line[1]));
      }
      buckets = new long[a.size()];
      for (int i = 0; i < a.size(); i++) {
        buckets[i] = a.get(i);
      }
    }
    init();
  }

  public HistogramGenerator(long[] buckets, int blockSize) {
    this.blockSize = blockSize;
    this.buckets = buckets;
    init();
  }

  private void init() {<FILL_FUNCTION_BODY>}

  @Override
  public Long nextValue() {
    int number = ThreadLocalRandom.current().nextInt((int) area);
    int i;

    for (i = 0; i < (buckets.length - 1); i++) {
      number -= buckets[i];
      if (number <= 0) {
        return (i + 1) * blockSize;
      }
    }

    return i * blockSize;
  }

  @Override
  public double mean() {
    return meanSize;
  }
}

    for (int i = 0; i < buckets.length; i++) {
      area += buckets[i];
      weightedArea += i * buckets[i];
    }
    // calculate average file size
    meanSize = ((double) blockSize) * ((double) weightedArea) / (area);
  
<methods>public non-sealed void <init>() ,public java.lang.Number lastValue() ,public abstract double mean() <variables>private java.lang.Number lastVal