mardi 24 février 2015

Output random words

I have to write a program that will output random words(with random letters) and that will not have 3 vocals or consonants near, so i wrote:


$array=array();

$n=10;



for ($i=0;$i<$n;$i++){
$l=rand(4,10); // $l=word length
?><br><?


for ($j=0;$j<$l;$j++){

$cas=rand(65,90); //$cas=random letters
$array[$j]=$cas;


if($j>1){
if (($array[$j-1]==65 || $array[$j-1]==69 || $array[$j-1]==73 || $array[$j-1]==79 || $array[$j-1]==85) ^ ($array[$j-2]==65|| $array[$j-2]==69 || $array[$j-2]==73 || $array[$j-2]==79 || $array[$j-2]==85)){ //will do XOR '^'


$cas=rand(65,90);
$array[$j]=$cas;

}
}

$m=chr($array[$j]);
echo $m;
}
}


?>


don't know why but it seems that IF doesn't work, 'cause when I output it'll print also words with 3 or more consonants or vocal. Can anybody help me? thanks :D and sorry for bad english :P





Aucun commentaire:

Enregistrer un commentaire