diff --git a/common/src/main/java/org/orecruncher/dsurround/lib/WeightTable.java b/common/src/main/java/org/orecruncher/dsurround/lib/WeightTable.java index 3395ac62..05e9a122 100644 --- a/common/src/main/java/org/orecruncher/dsurround/lib/WeightTable.java +++ b/common/src/main/java/org/orecruncher/dsurround/lib/WeightTable.java @@ -29,13 +29,7 @@ public static Optional makeSelection(final List> selec if (selections.size() == 1) return Optional.of(selections.getFirst().data()); - int totalWeight = WeightedRandom.getTotalWeight(selections); - - if (totalWeight == 0) - return Optional.empty(); - - int targetWeight = randomizer.nextInt(totalWeight); - return WeightedRandom.getWeightedItem(selections, targetWeight).map(IItem::data); + return WeightedRandom.getRandomItem(randomizer, selections).map(IItem::data); } public interface IItem extends WeightedEntry { diff --git a/common/src/main/java/org/orecruncher/dsurround/processing/fog/MorningFogRangeCalculator.java b/common/src/main/java/org/orecruncher/dsurround/processing/fog/MorningFogRangeCalculator.java index bc826ff9..980d397f 100644 --- a/common/src/main/java/org/orecruncher/dsurround/processing/fog/MorningFogRangeCalculator.java +++ b/common/src/main/java/org/orecruncher/dsurround/processing/fog/MorningFogRangeCalculator.java @@ -112,8 +112,9 @@ else if (this.seasonInfo.isWinter()) // Shouldn't get here, but... return FogDensity.NONE; - var totalWeight = WeightedRandom.getTotalWeight(selections); - var targetWeight = Randomizer.current().nextInt(totalWeight); - return WeightedRandom.getWeightedItem(selections, targetWeight).map(WeightedEntry.Wrapper::data).orElseThrow(); + return WeightedRandom + .getRandomItem(Randomizer.current(), selections) + .map(WeightedEntry.Wrapper::data) + .orElseThrow(); } } \ No newline at end of file