From ce1dafdfb5b8a3364060e12265b5fcb716750db2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Tue, 2 Jan 2024 13:19:16 +0100 Subject: [PATCH] Fix: Select random mode depending on PHP version --- src/Faker/Generator.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Faker/Generator.php b/src/Faker/Generator.php index ee58be35f4..ec285ce834 100644 --- a/src/Faker/Generator.php +++ b/src/Faker/Generator.php @@ -687,10 +687,22 @@ public function seed($seed = null) if ($seed === null) { mt_srand(); } else { - mt_srand((int) $seed, MT_RAND_PHP); + mt_srand((int) $seed, self::mode()); } } + /** + * @see https://www.php.net/manual/en/migration83.deprecated.php#migration83.deprecated.random + */ + private static function mode(): int + { + if (PHP_VERSION_ID < 80300) { + return MT_RAND_PHP; + } + + return MT_RAND_MT19937; + } + public function format($format, $arguments = []) { return call_user_func_array($this->getFormatter($format), $arguments);