nextLevelInRange method

num nextLevelInRange(
  1. num start,
  2. num end,
  3. int levels, {
  4. InverseCdf? inverseCdf,
})

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. If nGrid > 1 the interval is divided into an equidistant grid with nGrid points: [start + dx, start + 2 * dx, ..., end - dx] where dx = (end - start) / nGrid and any random number returned coincides with a gridpoint start 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 argument p 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();
}