Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. <?php
  2. function generuj_zbior($ilosc){
  3.  
  4.  
  5.  
  6. $ile=0;
  7. $zbior_liczb=array();
  8.  
  9.  
  10.  
  11. while($ile<$ilosc){
  12.  
  13. $ile++;
  14.  
  15. $zbior_liczb[]=$ile;
  16.  
  17. }
  18.  
  19. return $zbior_liczb;
  20.  
  21. }
  22.  
  23.  
  24.  
  25. function losuj_unikalne($zbior,$ile_wylosowac){
  26.  
  27.  
  28.  
  29. $wylosowane_liczby=array();
  30.  
  31.  
  32.  
  33.  
  34.  
  35. for($i=0;$i<$ile_wylosowac;$i++){
  36.  
  37. $wylosowany_index = array_rand($zbior,1);
  38. $wylosowane_liczby[]=$zbior[$wylosowany_index];
  39.  
  40. unset($zbior[$wylosowany_index]);
  41.  
  42. }
  43.  
  44. return $wylosowane_liczby;
  45.  
  46. }
  47.  
  48. $zbior = generuj_zbior(50);
  49.  
  50. $losowanie = losuj_unikalne($zbior,8);
  51.  
  52.  
  53.  
  54. echo '<pre>';
  55.  
  56. print_r($losowanie);
  57.  
  58. echo '</pre>';
  59.  
  60.  
  61.  
  62. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement