按权重随机排序
按权重随机排序 方案1,将list中每个实体的权重先取个随机值,然后在按随机后的权重排序。
public void sortList(List<Entity> list) {
if(list == null){
return;
}
list.forEach((Entity item) -> item.setWeight(random.nextInt(getWeight(item))));
Collections.sort(list,(Entity item1,Entity item2) -> getWeight(item2)- getWeight(item1));
}
private int getWeight(Entity item) {
Integer weight = item.getWeight();
weight = weight==null ? 0 : weight;
return weight;
}