Generating a unique sequence of number in PHP

For a project I had to randomize a given sequence of elements. Here’s the code for generate a unique sequence.

 

<?
$originalArray=array();
$randomizedArray=array();
$arraySize=10000;

for ($i=0; $i<$arraySize; $i++){
  array_push($originalArray, $i);
}

//var_dump($originalArray);
for ($i=0; $i<$arraySize; $i++){
$chosenIndex=rand(0, sizeof($originalArray)-1);
echo ‘chosen index: ‘.$chosenIndex.’, Value: ‘;
array_push($randomizedArray, $originalArray[$chosenIndex]);
//unset and update array size
unset($originalArray[$chosenIndex]);
$originalArray=array_values($originalArray);
echo $randomizedArray[$i].'<br>’;
}

?>

Advertisements