Advertisement
Guest User

tutaj dzbany karakany

a guest
Sep 23rd, 2019
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 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; $losC=0; $losS=0; $Avg2C=0; $Avg2S=0;
  27. for ($losowanko=0;$losowanko<$ileLosow;$losowanko++)
  28. {
  29. $losC=bindec(losBinC());
  30. $losS=bindec(losBinS());
  31. $StatC[$losC]++;
  32. $StatS[$losS]++;
  33. $Avg2C += $losC;
  34. $Avg2S += $losS;
  35. }
  36. $AvgC = 0; $AvgS = 0;
  37. for ($i=0;$i<=255;$i++) {
  38. $AvgC+=$StatC[$i]*$i;
  39. $AvgS+=$StatS[$i]*$i;
  40. }
  41. $AvgC /=$ileLosow;
  42. $AvgS /=$ileLosow;
  43.  
  44. echo "<p>Średnia z classic: $AvgC.<p>";
  45. echo "<p>Średnia z stringowania: $AvgS.<p>";
  46.  
  47. $Avg2C /=$ileLosow;
  48. $Avg2S /=$ileLosow;
  49.  
  50. echo "<h1>Druga metoda: </h1>";
  51. echo "<p>Średnia z classic: $Avg2C.<p>";
  52. echo "<p>Średnia z stringowania: $Avg2S.<p>";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement