3v4l.org

run code in 300+ PHP versions simultaneously
<?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 = ''; 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 7.1.0 - 7.1.33, 7.2.0 - 7.2.25, 7.3.0 - 7.3.12, 7.4.0
Word: php Seed: 7736 Test: php
Output for 5.2.1 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.25, 7.0.0 - 7.0.20
Word: php Seed: 24115 Test: php
Output for 4.3.0 - 4.3.11, 4.4.0 - 4.4.9, 5.0.0 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0
Word: php Seed: 58462 Test: php

preferences:
168.35 ms | 402 KiB | 246 Q