Return to Snippet

Revision: 1056
at September 5, 2006 23:46 by smilylion


Initial Code
function generate_numbers($min, $max, $anz)
{
     $array = range($min, $max);
     srand ((double)microtime()*1000000);
     for($x = 0; $x < $anz; $x++)
     {
          $i = rand(1, count($array))-1;
          $erg[] = $array[$i];
          array_splice($array, $i, 1);
     }
     return $erg;
}

// 5 eindeutige Zahlen im Bereich von 1 bis 100 ermitteln
$zufalls_array = generate_numbers(1, 100, 5);
echo join("; ", $zufalls_array);

Initial URL
http://www.php-faq.de/q/q-code-zufallszahlen.html

Initial Description

                                

Initial Title
random numbers between x and y

Initial Tags

                                

Initial Language
PHP