nextLevelInRange method
Generates a random floating point
value in the range from start
,
inclusive, to end
, exclusive.
start
: left boundary of the interval.end
: right boundary of the interval,start <= end
.inverseCdf
: inverse of the cummulative probability distribution function with non-zero support over the range [start, end).nGrid
: Number of grid points. IfnGrid > 1
the interval is divided into an equidistant grid withnGrid
points:[start + dx, start + 2 * dx, ..., end - dx]
wheredx = (end - start) / nGrid
and any random number returned coincides with a gridpointstart
exclusive,end
exclusive.
- If
inverseCdf == null
it is assumed that the values are uniformly distributed. - If
inverseCdf
is non-null, the random value is generated using:inverseCdf(nextDouble(), start, end)
. - Note: The function
inverseCdf(p, start, end)
must return a value in the range[start, end)
for each argumentp
in the range[0,1)
.
Implementation
num nextLevelInRange(
num start,
num end,
int levels, {
InverseCdf? inverseCdf,
}) {
inverseCdf ??= InverseCdfs.uniform;
final dx = (end - start) / (levels - 1);
final next = nextInRange(start, end, inverseCdf: inverseCdf);
return start + dx * ((next - start) / dx).round();
}