Unbias a random generator: Difference between revisions

m (→‎{{header|REXX}}: used a consistant style of alternating types of quoted strings.)
Line 77:
biased(integer bias)
{
return 1 ^ min(drand(bias - 1), 1);
}
 
Line 88:
}
 
return a;
}
 
Line 99:
b = 3;
while (b <= 6) {
i = cb = cu = 0;
cbwhile ((i += 0;1) <= n) {
cu = 0;
while (i < n) {
cb += biased(b);
cu += unbiased(b);
 
i += 1;
}
 
o_form("bias ~: /d2p2/%% vs /d2p2/%%\n", b, 100r * cb / n,
100r * cu / n);
 
b += 1;
}
 
return 0;
}</lang>
Output:<pre>bias 3: 33.51% vs 50.27%
Anonymous user