NormalDistribution.cpp 777 Bytes
Newer Older
1
#include "NormalDistribution.hpp"
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23


#define PI 3.14159265358979323846

void NormalDistribution::drawSample(const SampleID &id) {
    // Todo Alternative: Ziggurat algorithm
    if (internalCounter) {
        updateCounter();
        return;
    }
    double randNum1 = randNumberGen->sprng();
    double randNum2 = randNumberGen->sprng();
    firstSample = sqrt(-2.0 * log(randNum1)) * cos(2.0 * PI * randNum2);
    secondSample = sqrt(-2.0 * log(randNum1)) * sin(2.0 * PI * randNum2);
    updateCounter();
}

void NormalDistribution::updateCounter() {
    internalCounter = internalCounter + 1;
    internalCounter = internalCounter % 2;
}

24
Scalar NormalDistribution::EvalSample() {
25
26
27
28
29
    if (internalCounter)
        return firstSample;
    else
        return secondSample;
}