private int sample() { if (values.isEmpty()) { throw new ExactWeightedValueDepletedException("Exact weighted value depleted." + " It is configured to generate " + totalCount + " elements in total."); } int randomValue = distribution.nextInt(currentTotalCount); int sum = 0; for (int i = 0; i < counts.size(); i++) { sum += counts.get(i); if (randomValue < sum) { return i; } } throw new RuntimeException("If you see this exception. There is a bug in " + getClass().getName() + " class."); }
private int sample() { if (values.isEmpty()) { throw new ExactWeightedValueDepletedException("Exact weighted value depleted." + " It is configured to generate " + totalCount + " elements in total."); } int randomValue = distribution.nextInt(currentTotalCount); int sum = 0; for (int i = 0; i < counts.size(); i++) { sum += counts.get(i); if (randomValue < sum) { return i; } } throw new RuntimeException("If you see this exception. There is a bug in " + getClass().getName() + " class."); }