int (@NotNull GenerationEnvironment data, int @NotNull [] weights) { int totalWeight = Arrays.stream(weights).sum(); if (totalWeight == 0) return -1; int value = data.generate(Generator.integers(0, totalWeight)); for (int i = 0; i < weights.length; i++) { value -= weights[i]; if (value < 0) { return i; } } return -1; }