public Duration delay(int attempt) {
        if (attempt < 1) throw new IllegalArgumentException("Attempt must be positive");
        double currentDelay = attempt * initialDelay.toMillis();
        double delta = RANDOMIZATION_FACTOR * currentDelay;
        double lowerDelay = currentDelay - delta;
        double upperDelay = currentDelay + delta;
        long millis = (long) Math.min(lowerDelay + (random.nextDouble() * (upperDelay - lowerDelay + 1)),
                                      maxDelay.toMillis());
        return Duration.ofMillis(millis);
    }
@Test
    public void delay() {
        ExponentialBackoff b = new ExponentialBackoff(Duration.ofSeconds(1), Duration.ofSeconds(10), new Random(1000));
        assertEquals(List.of(Duration.ofMillis(1210),
                             Duration.ofMillis(2150),
                             Duration.ofMillis(4340),
                             Duration.ofMillis(2157),
                             Duration.ofMillis(4932)),
                     IntStream.rangeClosed(1, 5)
                              .mapToObj(b::delay)
                              .toList());
    }