static IntDistribution frequencyDistribution()

in src/main/java/org/jetbrains/jetCheck/IntDistribution.java [56:68]


  static IntDistribution frequencyDistribution(List<Integer> weights) {
    if (weights.isEmpty()) throw new IllegalArgumentException("No alternatives to choose from");
    
    int sum = weights.stream().reduce(0, (a, b) -> a + b);
    return new BoundedIntDistribution(0, weights.size() - 1, r -> {
      int value = r.nextInt(sum);
      for (int i = 0; i < weights.size(); i++) {
        value -= weights.get(i);
        if (value < 0) return i;
      }
      throw new IllegalArgumentException();
    });
  }