Skip to content

Instantly share code, notes, and snippets.

@mvisonneau
Created June 14, 2016 22:16
Show Gist options
  • Save mvisonneau/5b5cffb69b59c3858861a0e74277ac30 to your computer and use it in GitHub Desktop.
Save mvisonneau/5b5cffb69b59c3858861a0e74277ac30 to your computer and use it in GitHub Desktop.
generate_random_unique_range
<?php
$min = 1 ;
$max = 99999 ;
$array = range($min, $max);
function getRandomUnusedNumber( $array, $min, $max ) {
$i = rand( $min, $max ) ;
if( isset( $array[$i] ) )
return $array[$i] ;
else
return getRandomUnusedNumber( $array, $min, $max ) ;
}
for( $i=0; $i<$max-1; $i++ )
$result[$i] = getRandomUnusedNumber( $array, $min, $max ) ;
print_r( $result ) ;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment