Advertisement
Guest User

tutaj dzbanie

a guest
Sep 23rd, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. <?php
  2.  
  3. function losBinC($bit=8){
  4. $losBinC="";
  5. for ($bit=0;$bit<8;$bit++){
  6. $losBinC .= rand(0,1);
  7. //echo $losBinC."<br>";
  8. }
  9. return $losBinC;
  10. }
  11. //echo substr(str_shuffle("0000000011111111"),8);
  12. //echo bindec("1010");
  13.  
  14. function losBinS($bit=8) {
  15. $losBinS="";
  16. for($bit=0;$bit<8;$bit++)
  17. $losBinS .="01";
  18. $losBinS = substr(str_shuffle($losBinS),$bit);
  19. return $losBinS;
  20. }
  21. echo losBinS();
  22. for($i=0;$i<=255;$i++) {
  23. $StatC[$i]=0;
  24. $StatS[$i]=0;
  25. }
  26. $ileLosow=50000;
  27. for ($losowanko=0;$losowanko<$ileLosow;$losowanko++)
  28. {
  29. $StatC[bindec(losBinC())]++;
  30. $StatS[bindec(losBinS())]++;
  31. }
  32. $AvgC = 0; $AvgS = 0;
  33. for ($i=0;$i<=255;$i++) {
  34. $AvgC+=$StatC[$i]*$i;
  35. $AvgS+=$StatS[$i]*$i;
  36. }
  37. $AvgC /=$ileLosow;
  38. $AvgS /=$ileLosow;
  39.  
  40. echo "<p>Średnia z classic: $AvgC.<p>";
  41. echo "<p>Średnia z stringowania: $AvgS.<p>";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement