random numbers between x and y


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. function generate_numbers($min, $max, $anz)
  2. {
  3. $array = range($min, $max);
  4. srand ((double)microtime()*1000000);
  5. for($x = 0; $x < $anz; $x++)
  6. {
  7. $i = rand(1, count($array))-1;
  8. $erg[] = $array[$i];
  9. array_splice($array, $i, 1);
  10. }
  11. return $erg;
  12. }
  13.  
  14. // 5 eindeutige Zahlen im Bereich von 1 bis 100 ermitteln
  15. $zufalls_array = generate_numbers(1, 100, 5);
  16. echo join("; ", $zufalls_array);

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.