指定概率的一个算法
5个概率,分别返回值指定的一个数值,大家瞧瞧还有什么问题没。
private static Integer resizableProbabilityOf5(double p1, double p2, double p3, double p4, double p5) { if (p1 + p2 + p3 + p4 + p5 > 1) { throw new IllegalArgumentException("传入参数错误,概率之和不能大于1"); } Random r = new Random(); int n = r.nextInt(100000); int num = 0; int l1_resize = new Double((p1 < 0.00025 ? -(25 - p1 * 100000) : p1 * 100000 - 25)).intValue(); int l2_resize = new Double((p2 < 0.00025 ? -(25 - p2 * 100000) : p2 * 100000 - 25)).intValue(); int l3_resize = new Double((p3 < 0.00025 ? -(25 - p3 * 100000) : p3 * 100000 - 25)).intValue(); int l4_resize = new Double((p4 < 0.00025 ? -(25 - p4 * 100000) : p4 * 100000 - 25)).intValue(); int l5_resize = new Double((p5 < 0.00025 ? -(25 - p5 * 100000) : p5 * 100000 - 25)).intValue(); if (n < 25 + l1_resize) { num = 5; } else if (n >= 25 + l1_resize && n < 50 + l1_resize + l2_resize) { num = 4; } else if (n >= 50 + l1_resize + l2_resize && n < 75 + l1_resize + l2_resize + l3_resize) { num = 3; } else if (n >= 75 + l1_resize + l2_resize + l3_resize && n < 100 + l1_resize + l2_resize + l3_resize + l4_resize) { num = 2; } else if (n >= 100 + l1_resize + l2_resize + l3_resize + l4_resize && n < 125 + l1_resize + l2_resize + l3_resize + l4_resize + l5_resize) { num = 1; } return num; }
相关推荐
湾区人工智能 2020-11-20
Pokemogo 2020-11-16
baijingjing 2020-11-16
baijingjing 2020-11-15
Site 2020-11-07
lwnylslwnyls 2020-11-06
justaipanda 2020-11-05
MachineIntellect 2020-11-02
xueyuediana 2020-10-30
GeraldJones 2020-10-30
Tips 2020-10-29
baijingjing 2020-10-28
baijingjing 2020-10-27
硕鼠 2020-10-26
playoffs 2020-10-26
scuyxi 2020-10-25
playoffs 2020-10-25
yise001 2020-10-23