### Question:
Backoff { public static Stream<Long> decorrelatedJittered(long startMs, long maxMs) { final long startNanos = TimeUnit.NANOSECONDS.convert(startMs, TimeUnit.MILLISECONDS); final long maxNanos = TimeUnit.NANOSECONDS.convert(maxMs, TimeUnit.MILLISECONDS); return Stream.iterate(startMs, lastMs -> { long lastNanos = TimeUnit.MILLISECONDS.convert(lastMs, TimeUnit.NANOSECONDS); long randRange = Math.abs(lastNanos * 3 - startNanos); long randBackoff; if (0L == randRange) { randBackoff = startNanos; } else { randBackoff = startNanos + ThreadLocalRandom.current().nextLong(randRange); } long backOffNanos = Math.min(maxNanos, randBackoff); return TimeUnit.MILLISECONDS.convert(backOffNanos, TimeUnit.NANOSECONDS); }); }  static Stream<Long> constant(long startMs); static Stream<Long> exponential(long startMs,
                                           int multiplier,
                                           long maxMs); static Stream<Long> exponentialJittered(long startMs,
                                                   long maxMs); static Stream<Long> decorrelatedJittered(long startMs,
                                                    long maxMs); static Stream<Long> equalJittered(long startMs,
                                             long maxMs); static final Policy DEFAULT; }### Answer:
@Test public void testDecorrelatedJittered() throws Exception { long startMs = ThreadLocalRandom.current().nextLong(1L, 1000L); long maxMs = ThreadLocalRandom.current().nextLong(startMs, startMs * 2); Stream<Long> backoffs = Backoff.decorrelatedJittered(startMs, maxMs).limit(10); Iterator<Long> backoffIter = backoffs.iterator(); assertTrue(backoffIter.hasNext()); assertEquals(startMs, backoffIter.next().longValue()); AtomicLong prevMs = new AtomicLong(startMs); backoffIter.forEachRemaining(backoffMs -> { assertTrue(backoffMs >= startMs); assertTrue(backoffMs <= prevMs.get() * 3); assertTrue(backoffMs <= maxMs); prevMs.set(backoffMs); }); }