Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if(!function_exists("__")){
- function __($msg){
- $args = func_get_args();
- #print_r(debug_backtrace());
- if(count($args) > 1) $args = array_slice($args, 1);
- else $args = array();
- return vsprintf($msg, $args);
- }
- }
- global $W;
- $W = array(0.25, 0.125, 0.05, 0.01, 0.00);
- $CHECKS = array(500, 1000, 2500, 5000, 10000);
- $PROB = 0.95;
- echo __("\n[#] PROB=%d%%\n\n", $PROB*100);
- print_tr("-");
- print_row(array_merge(array(''), array_map(function($x){return $x > 0.0 ? ($x*100*2).'%' : 'max'; }, $W)));
- print_tr();
- foreach($CHECKS as $number_of_checks){
- $v = massive_check($PROB, $number_of_checks);
- $v = array_map(function($x){ return __("%.2f%%", $x);}, $v);
- array_unshift($v, str_pad(" ".$number_of_checks.":", 10));
- print_row($v);
- print_tr(($number_of_checks == $CHECKS[count($CHECKS)-1]) ? "-" : "+");
- }
- function print_row($v, $row_splitter="|"){
- echo '|'.implode($row_splitter, array_map(function($x){ return str_pad($x, 10, " ", STR_PAD_BOTH);}, $v)).'|' . "\n";
- }
- function print_tr($row_splitter="+"){
- global $W;
- #echo str_repeat("-", (count($W)+1)*10 + count($W) + 2)."\n";
- $r = array();
- for($i=1; $i<=count($W)+1; $i++){
- $r[] = str_repeat("-", 10);
- }
- print_row($r, $row_splitter);
- }
- function massive_check($prob, $number_of_checks){
- global $W;
- $diff = array();
- for($i=1; $i<=2000; $i++){
- $v = massive_say($prob, ($cnt_max=$number_of_checks));
- $diff[] = ($v-$prob)*100;
- }
- sort($diff);
- $values=array();
- foreach($W as $w){
- $values[] = (abs($diff[intval(count($diff)*$w)]) + abs($diff[intval(count($diff)*(1-$w))-1]));
- }
- return $values;
- }
- function massive_say($prob, $cnt_max=1000, $cnt_max2=100000){
- $yes = 0;
- for($i=0; $i<$cnt_max; $i++){
- $v=say_yes_or_no($prob, $cnt_max2);
- $yes += $v >= 1 ? 1 : 0;
- }
- return ($yes/$cnt_max);
- }
- function say_yes_or_no($prob, $max=100000){
- #mt_srand();
- return mt_rand(0, $max-1) < $max*$prob ? 1 : 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement