randomTimeDelayed static method

Future<void> randomTimeDelayed({
  1. required Duration minDuration,
  2. required Duration maxDuration,
})

minDuration - maxDuration 之间随机取值延时等待

Implementation

static Future<void> randomTimeDelayed({
  required Duration minDuration,
  required Duration maxDuration,
}) {
  assert(maxDuration.inMilliseconds >= minDuration.inMilliseconds);
  return Future.delayed(Duration(
    milliseconds: random.nextInt(
          maxDuration.inMilliseconds - minDuration.inMilliseconds,
        ) +
        minDuration.inMilliseconds,
  ));
}