轮盘赌介绍

算法实现
package test;
public class Test {
public static double[] multiPros;
public static void main(String[] args) {
multiPros = new double[4];
multiPros[0] = 0.14;
multiPros[1] = 0.49;
multiPros[2] = 0.06;
multiPros[3] = 0.31;
for (int i = 0; i < 10; i++) {
int k = nextDiscrete(multiPros);
System.out.println(k);
}
}
public static int nextDiscrete(double[] probs)
{
double sum = 0.0;
for (int i = 0; i < probs.length; i++)
sum += probs[i];
double r = Math.random() * sum;
sum = 0.0;
for (int i = 0; i < probs.length; i++) {
sum += probs[i];
if (sum > r)
return i;
}
return probs.length - 1;
}
}
结果展示
最后
以上就是光亮樱桃最近收集整理的关于轮盘赌算法的java实现算例轮盘赌介绍算法实现结果展示的全部内容,更多相关轮盘赌算法内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复