How to resolve the algorithm Unbias a random generator step by step in the PARI/GP programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Unbias a random generator step by step in the PARI/GP 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 PARI/GP programming language
Source code in the pari/gp programming language
randN(N)=!random(N);
unbiased(N)={
my(a,b);
while(1,
a=randN(N);
b=randN(N);
if(a!=b, return(a))
)
};
for(n=3,6,print(n"\t"sum(k=1,1e5,unbiased(n))"\t"sum(k=1,1e5,randN(n))))
You may also check:How to resolve the algorithm Flow-control structures step by step in the Comal programming language
You may also check:How to resolve the algorithm URL decoding step by step in the AppleScript programming language
You may also check:How to resolve the algorithm Old lady swallowed a fly step by step in the MAD programming language
You may also check:How to resolve the algorithm Determine if a string is squeezable step by step in the Kotlin programming language
You may also check:How to resolve the algorithm Sylvester's sequence step by step in the Swift programming language