1--TEST-- 2Random: Randomizer: shuffleBytes(): Basic functionality 3--FILE-- 4<?php 5 6use Random\Engine; 7use Random\Engine\Mt19937; 8use Random\Engine\PcgOneseq128XslRr64; 9use Random\Engine\Secure; 10use Random\Engine\Test\TestShaEngine; 11use Random\Engine\Xoshiro256StarStar; 12use Random\Randomizer; 13 14require __DIR__ . "/../../engines.inc"; 15 16$engines = []; 17$engines[] = new Mt19937(null, MT_RAND_MT19937); 18$engines[] = new Mt19937(null, MT_RAND_PHP); 19$engines[] = new PcgOneseq128XslRr64(); 20$engines[] = new Xoshiro256StarStar(); 21$engines[] = new Secure(); 22$engines[] = new TestShaEngine(); 23$length = getenv("SKIP_SLOW_TESTS") ? 1_000 : 5_000; 24 25function sort_bytes(string $bytes): string 26{ 27 $bytes = str_split($bytes); 28 sort($bytes); 29 return implode('', $bytes); 30} 31 32foreach ($engines as $engine) { 33 echo $engine::class, PHP_EOL; 34 35 $randomizer = new Randomizer($engine); 36 37 // This test is slow, test all numbers smaller than 50 and then in steps of 677 (which is prime). 38 for ($i = 1; $i < $length; $i += ($i < 50 ? 1 : 677)) { 39 $bytes = sort_bytes(random_bytes($i)); 40 41 $result = $randomizer->shuffleBytes($bytes); 42 43 $result = sort_bytes($result); 44 45 if ($result !== $bytes) { 46 die("failure: not a permutation at {$i}"); 47 } 48 } 49} 50 51die('success'); 52 53?> 54--EXPECTF-- 55Deprecated: Constant MT_RAND_PHP is deprecated in %s on line %d 56 57Deprecated: The MT_RAND_PHP variant of Mt19937 is deprecated in %s on line %d 58Random\Engine\Mt19937 59Random\Engine\Mt19937 60Random\Engine\PcgOneseq128XslRr64 61Random\Engine\Xoshiro256StarStar 62Random\Engine\Secure 63Random\Engine\Test\TestShaEngine 64success 65