5个概率,分别返回值指定的一个数值,大家瞧瞧还有什么问题没。
class="java" name="code">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; }
?