mardi 16 février 2016

Outputting 20 different random numbers within a range using php

I've created this code to output 20 random numbers from 5 to 100 in PHP. All the numbers must be different from each other. While executing I'm taking this error

enter image description here

This is my code:

<?php  

$a=array();
while(count($a)<20){
$found=false;
$random=rand(6,100);
for($i=0;$i<=count($a);$i++){
    if($a[$i]==$random){
        $found==true;
        break;
    }
}
if(!$found)
    $a[count($a)]=$random;


}
echo $a;

?>

Can someone help me to deal with this error? Thanks!




Aucun commentaire:

Enregistrer un commentaire