mirror of
https://github.com/Thorfusion/Mekanism-Community-Edition.git
synced 2026-11-22 04:52:25 +00:00
Introduce statistical consumption of gases.
This commit is contained in:
1 parent
e98026d78d
commit
a91dcc49d4
4 files changed
+46
-3
No files matched your search
@@ -0,0 +1,30 @@
|
||||
package mekanism.common.util;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import static java.lang.Math.ceil;
|
||||
import static java.lang.Math.sqrt;
|
||||
import static java.lang.Math.exp;
|
||||
import static java.lang.Math.pow;
|
||||
import static java.lang.Math.PI;
|
||||
import static java.lang.Math.E;
|
||||
|
||||
public class StatUtils
|
||||
{
|
||||
public static Random rand = new Random();
|
||||
|
||||
public static int inversePoisson(double mean)
|
||||
{
|
||||
double r = rand.nextDouble() * exp(mean);
|
||||
int m = 0;
|
||||
double p = 1;
|
||||
double stirlingValue = mean * E;
|
||||
double stirlingCoeff = 1 / sqrt(2 * PI);
|
||||
while ((p < r) && (m < 3*ceil(mean)))
|
||||
{
|
||||
m ++;
|
||||
p += stirlingCoeff/sqrt(m) * pow((stirlingValue/m), m);
|
||||
}
|
||||
return m;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user