25#ifndef quantlib_box_muller_gaussian_rng_h
26#define quantlib_box_muller_gaussian_rng_h
61 : uniformGenerator_(uniformGenerator) {}
69 typename RNG::sample_type s1 = uniformGenerator_.next();
70 x1 = s1.value*2.0-1.0;
71 firstWeight_ = s1.weight;
72 typename RNG::sample_type s2 = uniformGenerator_.next();
73 x2 = s2.value*2.0-1.0;
74 secondWeight_ = s2.weight;
76 }
while (
r>=1.0 ||
r==0.0);
78 ratio = std::sqrt(-2.0*std::log(
r)/
r);
79 firstValue_ = x1*ratio;
80 secondValue_ = x2*ratio;
81 weight_ = firstWeight_*secondWeight_;
84 return {firstValue_, weight_};
87 return {secondValue_, weight_};
Gaussian random number generator.
BoxMullerGaussianRng(const RNG &uniformGenerator)
Sample< Real > sample_type
sample_type next() const
returns a sample from a Gaussian distribution
ext::shared_ptr< YieldTermStructure > r