samples method
Returns an infinite source of random samples within the distribution.
Implementation
@override
Iterable<double> samples({Random? random}) sync* {
// https://en.wikipedia.org/wiki/Marsaglia_polar_method
const uniform = UniformDistribution(-1, 1);
for (;;) {
double p1, p2, p;
do {
p1 = uniform.sample(random: random);
p2 = uniform.sample(random: random);
p = p1 * p1 + p2 * p2;
} while (p >= 1);
p = sigma * sqrt(-2 * log(p) / p);
yield mu + p1 * p;
yield mu + p2 * p;
}
}