Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,36 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
// just generate 0s and 1s without storing them
|
||||
double run_test(double p, int len, int runs)
|
||||
{
|
||||
int r, x, y, i, cnt = 0, thresh = p * RAND_MAX;
|
||||
|
||||
for (r = 0; r < runs; r++)
|
||||
for (x = 0, i = len; i--; x = y)
|
||||
cnt += x < (y = rand() < thresh);
|
||||
|
||||
return (double)cnt / runs / len;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
double p, p1p, K;
|
||||
int ip, n;
|
||||
|
||||
puts( "running 1000 tests each:\n"
|
||||
" p\t n\tK\tp(1-p)\t diff\n"
|
||||
"-----------------------------------------------");
|
||||
for (ip = 1; ip < 10; ip += 2) {
|
||||
p = ip / 10., p1p = p * (1 - p);
|
||||
|
||||
for (n = 100; n <= 100000; n *= 10) {
|
||||
K = run_test(p, n, 1000);
|
||||
printf("%.1f\t%6d\t%.4f\t%.4f\t%+.4f (%+.2f%%)\n",
|
||||
p, n, K, p1p, K - p1p, (K - p1p) / p1p * 100);
|
||||
}
|
||||
putchar('\n');
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue