well i have a use for rand();
I need to rand from 1 to x amount 4 times and make sure the value will not return.
This is my code corrently:
$Count = 15;
$secondstage = '';
$arrayindex = '';
for($i=1; $i<5; $i++){
$arrayindex = rand(1,$Count);
if($secondstage == $arrayindex){
for($b=1; $arrayindex == $secondstage; $b++){
$arrayindex = rand(1,$Count);
}
}
$secondstage = $arrayindex;
echo $secondstage;
echo '<br>';
}
Am I having some logic mistake here? I thought of maybe using while but for should also work.
So basically you want 4 random non-repeating numbers between 1 and 15, inclusive? You’re using way too much code for that. A simpler version: