- microtime: documentation ( source)
- rand: documentation ( source)
- srand: documentation ( source)
<?php
function random($car) {
$string = "";
$chaine = "abcdefghijklmnpqrstuvwxy";
srand((double)microtime()*1000000);
for($i=0; $i<$car; $i++) {
$string .= $chaine[rand()%strlen($chaine)];
}
return $string;
}
$nombreDeTentative = 0;
while(random(4) != "samu")
{
$nombreDeTentative++;
}
echo "Le nombre de tentative pour trouver samu est de ".$nombreDeTentative;
?>