背景
    package com.wener.security.exp;
    import lombok.Data;
    import java.util.HashMap;
    import java.util.Map;
    /* 平滑加权轮循算法 @author ken @version 1.0 /public class WeightRandom {
    public WeightRandom() {
    }
    private static Map machineMap = new HashMap<>(); // 集合中取权重之和 private int weightSum(Map map) {
    int sum = 0; for (Integer weight : map.values()) {
    sum += weight; }
    return sum; }
    // 集合中取权重之和 private Map weightMax(Map map) {
    Map retMap = null; for (Integer weight : map.values()) {
    }
    return null; }
    public String weightRandom(Map map) {
    // 初始化 if (machineMap.isEmpty()) {
    map.forEach((ip, weitht) -> {
    machineMap.put(ip, new Machine(ip, weitht, 0)); }); }
    machineMap.forEach((ip, weight) -> {
    weight.setCurrentWeight(weight.getCurrentWeight() + weight.getWeight()); }); Machine machine = null; for (Machine machineEl : machineMap.values()) {
    if (machine == null || machine.getCurrentWeight() < machineEl.getCurrentWeight()) {
    machine = machineEl; }
    }
    // 取权重之和 Integer weightSum = weightSum(map); machine.setCurrentWeight(machine.getCurrentWeight() - weightSum); // 取最大的权重 System.err.println(machine.getIp()); return “”; }
    @Data class Machine {
    public Machine() {
    }
    public Machine(String ip, Integer weight, Integer currentWeight) {
    this.ip = ip; this.weight = weight; this.currentWeight = currentWeight; }
    private String ip; private Integer weight; private Integer currentWeight; }
    }