1--TEST-- 2Random: Randomizer: The Mt19937 engine is a drop-in replacement for mt_rand() 3--FILE-- 4<?php 5 6use Random\Randomizer; 7use Random\Engine\Mt19937; 8 9echo "MT_RAND_PHP", PHP_EOL; 10 11$randomizer = new Randomizer(new Mt19937(1234, MT_RAND_PHP)); 12mt_srand(1234, MT_RAND_PHP); 13 14for ($i = 0; $i < 10_000; $i++) { 15 if ($randomizer->nextInt() !== mt_rand()) { 16 die("failure: state differs at {$i} for nextInt()"); 17 } 18} 19 20for ($i = 0; $i < 10_000; $i++) { 21 if ($randomizer->getInt(0, $i) !== mt_rand(0, $i)) { 22 die("failure: state differs at {$i} for getInt()"); 23 } 24} 25 26echo "MT_RAND_MT19937", PHP_EOL; 27 28$randomizer = new Randomizer(new Mt19937(1234, MT_RAND_MT19937)); 29mt_srand(1234, MT_RAND_MT19937); 30 31for ($i = 0; $i < 10_000; $i++) { 32 if ($randomizer->nextInt() !== mt_rand()) { 33 die("failure: state differs at {$i} for nextInt()"); 34 } 35} 36 37for ($i = 0; $i < 10_000; $i++) { 38 if ($randomizer->getInt(0, $i) !== mt_rand(0, $i)) { 39 die("failure: state differs at {$i} for getInt()"); 40 } 41} 42 43die('success'); 44 45?> 46--EXPECT-- 47MT_RAND_PHP 48MT_RAND_MT19937 49success 50