Skip to content

Instantly share code, notes, and snippets.

@michalskop
Created December 19, 2012 23:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michalskop/4341687 to your computer and use it in GitHub Desktop.
Save michalskop/4341687 to your computer and use it in GitHub Desktop.
<?php
/**
* Simulate random selection of sheets with given probabilities of number of errors on them
*/
$path = '';
$n_file_str = 'n.csv';
$result_file = fopen('result.csv',"w");
//probability of errors in one sheet - based on Okamura
$p_errors = array(
0.4837621257,
0.7043441586,
0.8114719528,
0.8616617461,
0.8852804724,
0.9025727541,
0.9126950654,
0.9215520877,
1
);
for ($i=1;$i<=50000;$i++) {
$n = 0;
for ($j=1;$j<=1063;$j++) {
$rand = rand(0,10000000)/10000000;
for ($k=0;$k<count($p_errors);$k++) {
if ($rand < $p_errors[$k]) {
$n += $k;
break;
}
}
}
fwrite($result_file,$n."\n");
}
fclose($result_file);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment