RandomUtil.weightRandom
权重随机生成器,传入带权重的对象,然后根据权重随机获取对象
importcn.hutool.core.lang.WeightRandom; importcn.hutool.core.util.RandomUtil; importjava.util.ArrayList; importjava.util.List; publicclassTest { publicstaticvoidmain(String[] args) { List<WeightRandom.WeightObj<Integer>>a=newArrayList<>(); a.add(newWeightRandom.WeightObj<>(1, 20)); a.add(newWeightRandom.WeightObj<>(2,33)); a.add(newWeightRandom.WeightObj<>(3,33)); a.add(newWeightRandom.WeightObj<>(4,50)); System.out.println(RandomUtil.weightRandom(a).next()); } }