fork download
  1. <?php
  2.  
  3. $x = Array('a','b','c','d','e');
  4. $y = Array();
  5. $c = count($x);
  6. foreach($x as $i=>$a){
  7. for($s = 0; $s < $c-$i; $s++){
  8. $y[] = $a;
  9. }
  10. }
  11. $b = Array('a'=>0,'b'=>0,'c'=>0,'d'=>0,'e'=>0);
  12. $k=100000;
  13. for($u = 0; $u < $k; $u++){
  14. $r = array_rand($y);
  15. $n = $y[$r];
  16.  
  17. $b[$n]++;
  18. }
  19. foreach($b as &$u) $u=$u/($k/count($y));
  20. ksort($b);
  21. print_r($b);
Success #stdin #stdout 0.13s 52480KB
stdin
Standard input is empty
stdout
Array
(
    [a] => 4.9809
    [b] => 4.0047
    [c] => 3.03
    [d] => 2.0112
    [e] => 0.9732
)