<?php
error_reporting(-1);
set_time_limit(0);
generate_nice('php');
function generate_nice($word) {
echo 'Word: ', $word, "\n";
$i = generate($word);
echo 'Seed: ', $i, "\n";
echo 'Test: ', test($i, strlen($word)), "\n";
}
function generate($word) {
$l = strlen($word);
$s = '';
for ($i = 0; $s !== $word; ++$i) {
$s = '';
srand($i);
for ($j = 0; $j < $l; ++$j) {
$s .= chr(96 + rand(1, 26));
}
}
return $i - 1;
}
function test($i, $l) {
$s = '';
srand($i);
for ($j = 0; $j < $l; ++$j) {
$s .= chr(96 + rand(1, 26));
}
return $s;
}
preferences:
31.82 ms | 402 KiB | 5 Q