blob: 4e8bc0fb9bd6c5b6caaf52b16b34dd66113c9b29 (
plain)
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
import java.util.Random;
public class RandomDistribution
{
public static int normalDistributionInt(int min, int max)
{
int result;
do
{
result = (int) Math.round(boxMuller() * 100);
}
while(result < min || result > max);
return result;
}
private static double boxMuller()
{
Random rand = new Random();
double u = rand.nextDouble();
double v = rand.nextDouble();
return Math.sqrt(-2 * (Math.log(u)/Math.log(Math.E))) * Math.cos(2 * Math.PI * v);
}
public static int laplaceDistributionInt(int min, int max)
{
int result;
do
{
result = (int) Math.round(laplaceDistribution() * 100);
}
while(result < min || result > max);
return result;
}
private static double laplaceDistribution()
{
Random rand = new Random();
double u = rand.nextDouble() - 0.5;
return 0 - (Math.signum(u) * Math.log(1 - (2 * Math.abs(u))));
}
public static int uniformDistributionInt(int min, int max)
{
Random rand = new Random();
return rand.nextInt((max - min) + 1) + min;
}
public static int clockDistribution(int min, int max, int hWidth, int lWidth)
{
int result;
do
{
result = uniformDistributionInt(min, max);
int modResult = result % (hWidth + lWidth);
if(modResult < hWidth)
{
break;
}
else
{
if(uniformDistributionInt(0,1) == 1)
{
break;
}
}
}
while(true);
return result;
}
}
|