LongSampler { public void setVariance(double variance) { this.variance = variance; } LongSampler(long init);  LongSampler(long init, double variance);  LongSampler(long init, double variance, Long min, Long max); long getValue(); void setVariance(double variance); void setMax(long max); void setMin(long min); @Override String toString();  }
@Test public void test() { LongSampler sampler = new LongSampler(5); sampler.setVariance(3); Map<Long, Long> histograms = Stream.generate(sampler::getValue) .limit(10000) .collect(Collectors.groupingBy(Function.identity(), Collectors.counting())); Optional<Map.Entry<Long, Long>> max = histograms.entrySet().stream() .max(Comparator.comparingLong(Map.Entry::getValue)); assertThat(max).isPresent(); assertThat(max.get().getKey()).isEqualTo(5); }