Skip to content

Commit 303d454

Browse files
committed
fix: replace rand() with random_int() and intdiv() in getTimeoutMicroseconds()
rand() (mt_rand) offers weaker uniformity than random_int(), and passing $timeout / 10 (float) to rand()'s int parameters triggers a deprecation warning in PHP 8.1+. Switch to random_int() for better distribution and use intdiv() to ensure the upper bound is always an integer.
1 parent 6f497b5 commit 303d454

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

src/ExponentialBackoff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ public static function getTimeoutMicroseconds(int $iteration, int $initialTimeou
189189
$timeout = $initialTimeout * (1 << --$iteration);
190190

191191
// We throw in some randomness here to try to prevent connections from colliding
192-
return $timeout + rand(0, $timeout / 10);
192+
return $timeout + random_int(0, intdiv($timeout, 10));
193193
}
194194

195195
protected function increaseCurrentAttempts(): self

0 commit comments

Comments
 (0)