sample method
Returns a single sample of a random value within the distribution.
Implementation
@override
double sample({Random? random}) {
const normal = NormalDistribution.standard();
const uniform = UniformDistribution.standard();
final correctedShape = shape < 1 ? shape + 1 : shape;
double u, v, x;
final a1 = correctedShape - 1 / 3;
final a2 = 1 / sqrt(9 * a1);
do {
do {
x = normal.sample(random: random);
v = 1 + a2 * x;
} while (v <= 0);
v = v * v * v;
u = uniform.sample(random: random);
} while (u > 1 - 0.331 * pow(x, 4) &&
log(u) > 0.5 * x * x + a1 * (1 - v + log(v)));
if (shape == correctedShape) {
return a1 * v * scale;
}
do {
u = uniform.sample(random: random);
} while (u == 0);
return pow(u, 1 / shape) * a1 * v * scale;
}