private double gamma double double Random rand double temp sum double

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
private double gamma(double k, double a, Random rand)
{
double temp = 0, sum = 0;
double r,z,y,result=0;
temp = k - (int) k;
z = beta(1 - temp, k,rand);
for (int i = 0; i < (int)k; i++)
{
r = rand.NextDouble();
sum += Math.Log(r);
}
y = rand.NextDouble();
result = -sum + (z - 1) * Math.Log(y);
return result;
}