3v4l.org

run code in 300+ PHP versions simultaneously
<?php function my_mt_srand(?int $seed = null) { $GLOBALS['my_mt_rand'] = new \Random\Randomizer(new \Random\Engine\Mt19937($seed)); } function my_mt_rand($min = null, $max = null) { if (!isset($GLOBALS['my_mt_rand'])) { $GLOBALS['my_mt_rand'] = new \Random\Randomizer(new \Random\Engine\Mt19937()); } if ($min === null && $max === null) { return $GLOBALS['my_mt_rand']->nextInt(); } return $GLOBALS['my_mt_rand']->getInt($min, $max); } mt_srand(1234); my_mt_srand(1234); var_dump(mt_rand()); var_dump(my_mt_rand()); var_dump(mt_rand(1, 1000)); var_dump(my_mt_rand(1, 1000));
Output for 8.2.0 - 8.2.10
int(411284887) int(411284887) int(172) int(172)
Output for 8.0.1 - 8.0.30, 8.1.0 - 8.1.23
Fatal error: Uncaught Error: Class "Random\Randomizer" not found in /in/B18he:4 Stack trace: #0 /in/B18he(19): my_mt_srand(1234) #1 {main} thrown in /in/B18he on line 4
Process exited with code 255.

preferences:
93.7 ms | 402 KiB | 69 Q