Advertisement
roniewill

30 Mil números aleatórios de 1 a 50 mil sem repetição

Aug 6th, 2017
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.63 KB | None | 0 0
  1. <?php
  2.  
  3. function microtime_float()
  4. {
  5.     list($usec, $sec) = explode(" ", microtime());
  6.     return ((float)$usec + (float)$sec);
  7. }
  8.  
  9.  
  10. /**
  11.  * 30 Mil números aleatórios de 1 a 50 mil sem repetição
  12.  */
  13. $time_start = microtime_float();
  14.  
  15. function randomGen($min, $max, $quantity) {
  16.     $numbers = range($min, $max);
  17.     shuffle($numbers);
  18.     return array_unique($numbers);
  19. }
  20.  
  21. $arr = randomGen(0,50000,30000);
  22. $val = "";
  23. foreach ($arr as $key => $value) {
  24.     $val .= $value.'<br>';
  25. }
  26. echo $val;
  27.  
  28. $time_end = microtime_float();
  29. $time = round($time_end - $time_start, 5);
  30.  
  31. echo "<br><br>Tempo de execucao: $time segundos\n";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement