Skip to content

Instantly share code, notes, and snippets.

@schleumer
Created March 12, 2013 00:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save schleumer/5139373 to your computer and use it in GitHub Desktop.
Save schleumer/5139373 to your computer and use it in GitHub Desktop.
Generate an array with $quantity random numbers from the given range (from $x to $y)
<?php
/**
* Generate an array with $quantity random numbers from the given range (from $x to $y)
* @param int $min
* @param int $max
* @param int $quantity
* @return array
*/
function generateNumbers($min, $max, $quantity) {
$array = range($min, $max);
for ($x = 0; $x <= $quantity; $x++) {
unset($array[array_rand($array)]);
}
return $array;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment