OSDN Git Service

Merge branch 'master' of https://scm.sourceforge.jp/gitroot/chemicraft/chemicraft
[chemicraft/chemicraft.git] / common / chemicraft / util / MathHelperPlus.java
1 package chemicraft.util;
2
3 import java.util.ArrayList;
4 import java.util.Random;
5
6 public class MathHelperPlus
7 {
8
9         public static MathHelperPlus instance = new MathHelperPlus();
10
11         /** 
12          * Return probability(0~).
13          */
14         public static int Probability(double... par1)
15         {
16                 ArrayList<Double> var1 = new ArrayList<Double>();
17                 for (int var2 = 0; var2 < par1.length; var2++){
18                         var1.add(par1[var2]);
19                 }
20                 return Probability(var1);
21         }
22
23         public static int Probability(int... par1)
24         {
25                 ArrayList<Double> var1 = new ArrayList<Double>();
26                 for (int var2 = 0; var2 < par1.length; var2++){
27                         var1.add((double)par1[var2]);
28                 }
29                 return Probability(var1);
30         }
31
32         public static int Probability(ArrayList<Double> par1)
33         {
34                 Random var2 = new Random();
35                 int var3 = var2.nextInt(100);
36                 double var4 = 0.0D;
37
38                 for (int var5 = 0; var5 < par1.size(); var5++) {
39                         var4 += par1.get(var5);
40                 }
41
42                 ArrayList<Double> var6 = new ArrayList<Double>();
43                 for (int var7 = 0; var7 < par1.size(); var7++) {
44                         var6.add(par1.get(var7) / var4 * 100);
45                 }
46
47                 double var8 = 0.0D;
48                 for (int var9 = 0; var9 < var6.size(); var9++) {
49                         if (var3 < var6.get(var9) + var8) {
50                                 return var9;
51                         } else {
52                                 var8 += var6.get(var9);
53                         }
54                 }
55                 return var3;
56         }
57
58 }