How to resolve the algorithm Unbias a random generator step by step in the Quackery programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Unbias a random generator step by step in the Quackery 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 Quackery programming language
Source code in the quackery programming language
$ "bigrat.qky" loadfile
[ random 0 = ] is randN ( n --> n )
[ dup randN
over randN
2dup = iff
2drop again
drop nip ] is unbias ( n --> n )
[ dup echo say " biased --> "
0
1000000 times
[ over randN if 1+ ]
nip 1000000 6 point$ echo$ ] is showbias ( n --> )
[ dup echo say " unbiased --> "
0
1000000 times
[ over unbias if 1+ ]
nip 1000000 6 point$ echo$ ] is showunbias ( n --> )
' [ 3 4 5 6 ]
witheach
[ dup cr
showbias cr
showunbias cr ]
You may also check:How to resolve the algorithm Sorting algorithms/Stooge sort step by step in the Quackery programming language
You may also check:How to resolve the algorithm Temperature conversion step by step in the Scheme programming language
You may also check:How to resolve the algorithm Ascending primes step by step in the Delphi programming language
You may also check:How to resolve the algorithm Catalan numbers step by step in the Eiffel programming language
You may also check:How to resolve the algorithm Lucky and even lucky numbers step by step in the Tcl programming language