OSDN Git Service

Merge branch 'master' of https://scm.sourceforge.jp/gitroot/chemicraft/chemicraft
[chemicraft/chemicraft.git] / common / pcc / chemicraft / util / MathHelperPlus.java
1 package pcc.chemicraft.util;
2
3 import java.util.ArrayList;
4 import java.util.Random;
5
6 public class MathHelperPlus {
7
8         public static Random rand = new Random();
9
10         /**
11          * Return probability(0~).
12          */
13         public static int probability(double... par1) {
14                 ArrayList<Double> var1 = new ArrayList<Double>();
15                 for (int var2 = 0; var2 < par1.length; var2++) {
16                         var1.add(par1[var2]);
17                 }
18                 return probability(var1);
19         }
20
21         public static int probability(ArrayList<Double> par1) {
22                 for (int i = 0; i < par1.size(); i++) {
23                         double var1 = par1.get(i) / 100;
24                         double var2 = Math.random();
25                         if (var1 <= var2) {
26                                 return i;
27                         } else {
28                                 continue;
29                         }
30                 }
31                 return -1;
32         }
33
34 }