Simple random number based on weight load balancing algorithm

datastructure.loadbalance Package; 

Import of java.util.ArrayList; 
Import java.util.List; 
Import java.util.Random; 

/ ** 
 * <H3> netty_lecture </ H3> 
 * <P> simple routing algorithm weights </ p> 
 * 
 * @author: Myron 
 * @date: 2020-03-19 22:09 
 ** / 
public class MiGong { 
    Private static int the WEIGHT = Final. 7; 

    public static void main (String [] args) { 
        the Random Random the Random new new = ( ); 
        / ** List analog weight distribution * / 
        List <Integer> = new new List the ArrayList <> (); 
        List.add (. 5); 
        List.add (. 3); 
        List.add (2); 
        / ** is offset the number randomly generated weight * / 
        int offset = random.nextInt (the wEIGHT);
        offsetCopy offset = int; 
        for (int I = 0; I <list.size (); I ++) { 
            offset - = List.get (I); 
            // traversed here compared; when the offset <0, offset described here falls 
            IF (offset <0) { 
                System.out.printf ( "% d weight falling interval:% d -% d", offsetCopy, 0, list.get (i) + list.get (i -1)); 
                return; 
            } 
        } 
    }

  

Guess you like

Origin www.cnblogs.com/mmh760/p/12533270.html