HI, this is the algorithm I create it, hope it will be of good use.
$totalData =count($allData);
$randIndex = array();
for($i=0;$i<$totalData;$i++)
{
$randIndex[$i]= rand(0,$totalData-1) ;
do{
$hasIt = false;
for($j=0;$j<$i;$j++)
{
if($randIndex[$j]==$randIndex[$i])
{
$randIndex[$i]=rand(0,$totalData-1) ;
$hasIt = true;
}
}
}while($hasIt);
}
SO, for your output result:
for($i=0;$i<$totalData;$i++)
{
echo $randIndex[$i];
}
Advertisement