<?php
error_reporting(-1);
set_time_limit(0);
generate_nice('hello');
generate_nice('world');
function generate_nice($word) {
echo 'Word: ', $word, PHP_EOL;
$i = generate($word);
echo 'Seed: ', $i, PHP_EOL;
echo 'Test: ', test($i, strlen($word)), PHP_EOL;
}
function generate($word) {
$l = strlen($word);
$s = '';
for ($i = 0; $s !== $word; ++$i) {
$s = '';
mt_srand($i);
for ($j = 0; $j < $l; ++$j) {
$s .= chr(96 + mt_rand(1, 26));
}
}
return $i - 1;
}
function test($i, $l) {
$s = '';
mt_srand($i);
for ($j = 0; $j < $l; ++$j) {
$s .= chr(96 + mt_rand(1, 26));
}
return $s;
}
- Output for 5.3.0 - 5.3.22, 5.4.0 - 5.4.12, 7.0.20, 7.1.5 - 7.1.7
- Word: hello
Process exited with code 137.
preferences:
69.68 ms | 402 KiB | 45 Q