-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathRandom.java
55 lines (41 loc) · 1.41 KB
/
Random.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/* Holds random number genator necessities */
/* Trying to encapsulate this, so the RNG particulars can be changed if necessary */
/* Completely static class, allows no instances to be instantiated */
//import cern.jet.random.*;
import java.util.*;
public class Random {
// methods
public static int nextInt(int from, int to) {
return cern.jet.random.Uniform.staticNextIntFromTo(from, to);
}
public static double nextDouble() {
return cern.jet.random.Uniform.staticNextDouble();
}
public static double nextDouble(double from, double to) {
return cern.jet.random.Uniform.staticNextDoubleFromTo(from, to);
}
public static double nextNormal() {
return cern.jet.random.Normal.staticNextDouble(0.0,1.0);
}
public static double nextNormal(double mean, double sd) {
return cern.jet.random.Normal.staticNextDouble(mean,sd);
}
// tuned with mean
public static double nextExponential(double lambda) {
return cern.jet.random.Exponential.staticNextDouble(1.0/lambda);
}
// tuned with alpha and beta, matching Mathematica's notation
public static double nextGamma(double alpha, double beta) {
return cern.jet.random.Gamma.staticNextDouble(alpha, 1/beta);
}
public static int nextPoisson(double lambda) {
return cern.jet.random.Poisson.staticNextInt(lambda);
}
public static boolean nextBoolean(double p) {
boolean x = false;
if (nextDouble() < p) {
x = true;
}
return x;
}
}