Posted By

smilylion on 09/05/06


Tagged

random


Versions (?)

random numbers between x and y


 / Published in: PHP
 

URL: http://www.php-faq.de/q/q-code-zufallszahlen.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);

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: alexy on February 17, 2010

Wow. I've been looking for this for over a year! +1 for this :D

You need to login to post a comment.