Created
June 14, 2016 22:16
-
-
Save mvisonneau/5b5cffb69b59c3858861a0e74277ac30 to your computer and use it in GitHub Desktop.
generate_random_unique_range
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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