How to resolve the algorithm Unbias a random generator step by step in the Aime programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Unbias a random generator step by step in the Aime programming language
Table of Contents
Problem Statement
The actual unbiasing should be done by generating two numbers at a time from randN and only returning a 1 or 0 if they are different. As long as you always return the first number or always return the second number, the probabilities discussed above should take over the biased probability of randN. This task is an implementation of Von Neumann debiasing, first described in a 1951 paper.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Unbias a random generator step by step in the Aime programming language
Source code in the aime programming language
integer
biased(integer bias)
{
1 ^ min(drand(bias - 1), 1);
}
integer
unbiased(integer bias)
{
integer a;
while ((a = biased(bias)) == biased(bias)) {
}
a;
}
integer
main(void)
{
integer b, n, cb, cu, i;
n = 10000;
b = 3;
while (b <= 6) {
i = cb = cu = 0;
while ((i += 1) <= n) {
cb += biased(b);
cu += unbiased(b);
}
o_form("bias ~: /d2p2/%% vs /d2p2/%%\n", b, 100r * cb / n,
100r * cu / n);
b += 1;
}
0;
}
You may also check:How to resolve the algorithm Abelian sandpile model step by step in the Haskell programming language
You may also check:How to resolve the algorithm Guess the number/With feedback step by step in the Common Lisp programming language
You may also check:How to resolve the algorithm Integer sequence step by step in the Bracmat programming language
You may also check:How to resolve the algorithm History variables step by step in the J programming language
You may also check:How to resolve the algorithm Taxicab numbers step by step in the C++ programming language