//创建一个分发器
RandomDispatcher randomDispatcher = new RandomDispatcher();
//设置每种事件的概率,注意,概率之和不一定是100哦
randomDispatcher.put(20, 1);
randomDispatcher.put(1, 2);
randomDispatcher.put(29, 3);
randomDispatcher.put(50, 4);
//随机
int retIndex = randomDispatcher.random();
//根据随机结果去执行不同的方法
switch (retIndex) {
case 1:
System.out.println("do method A");
break;
case 2:
System.out.println("do method B");
break;
case 3:
System.out.println("do method C");
break;
case 4:
System.out.println("do method D");
break;
default:
break;
}