delayFor method
Delay to wait before attempt number attempt (1-based; the delay before
the second attempt is delayFor(1)).
Implementation
Duration delayFor(int attempt) {
final scaled =
initialDelay.inMilliseconds * pow(backoffFactor, attempt - 1);
final capped = min(scaled.toDouble(), maxDelay.inMilliseconds.toDouble());
if (jitter <= 0) return Duration(milliseconds: capped.round());
// Deterministic-free jitter is fine here; this only spreads load.
final spread = capped * jitter;
final value = capped - spread + Random().nextDouble() * spread * 2;
return Duration(milliseconds: max(0, value).round());
}