1--TEST-- 2Random: Randomizer: getBytesFromString(): 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 24foreach ($engines as $engine) { 25 echo $engine::class, PHP_EOL; 26 27 $randomizer = new Randomizer($engine); 28 var_dump($randomizer->getBytesFromString('a', 10)); 29 var_dump($randomizer->getBytesFromString(str_repeat('a', 256), 5)); 30 31 for ($i = 1; $i < 250; $i++) { 32 $output = $randomizer->getBytesFromString(str_repeat('ab', $i), 500); 33 34 // This check can theoretically fail with a chance of 0.5**500. 35 if (!str_contains($output, 'a') || !str_contains($output, 'b')) { 36 die("failure: didn't see both a and b at {$i}"); 37 } 38 } 39} 40 41die('success'); 42 43?> 44--EXPECTF-- 45Deprecated: Constant MT_RAND_PHP is deprecated in %s on line %d 46 47Deprecated: The MT_RAND_PHP variant of Mt19937 is deprecated in %s on line %d 48Random\Engine\Mt19937 49string(10) "aaaaaaaaaa" 50string(5) "aaaaa" 51Random\Engine\Mt19937 52string(10) "aaaaaaaaaa" 53string(5) "aaaaa" 54Random\Engine\PcgOneseq128XslRr64 55string(10) "aaaaaaaaaa" 56string(5) "aaaaa" 57Random\Engine\Xoshiro256StarStar 58string(10) "aaaaaaaaaa" 59string(5) "aaaaa" 60Random\Engine\Secure 61string(10) "aaaaaaaaaa" 62string(5) "aaaaa" 63Random\Engine\Test\TestShaEngine 64string(10) "aaaaaaaaaa" 65string(5) "aaaaa" 66success 67