generate method
An adaptation of the code in package:normal
, with tighter types,
better performance and a lazy iterable instead of a List.
Generates random data drawn from a normal distribution through
the Box-Muller algorithm.
Implementation
Iterable<double> generate() sync* {
_Pair makePair() {
final u1 = _random.nextDouble(),
u2 = _random.nextDouble(),
r = sqrt(-2 * log(u1)),
t = 2 * pi * u2;
return _Pair(r * cos(t), r * sin(t));
}
while (true) {
final pair = makePair();
yield pair.a * standardDeviation + mean;
yield pair.b * standardDeviation + mean;
}
}