Unbias a random generator: Difference between revisions

Content added Content deleted
(→‎{{header|PARI/GP}}: Marked incomplete as missing the randN column)
Line 653: Line 653:


=={{header|PARI/GP}}==
=={{header|PARI/GP}}==
{{incomplete|PARI/GP|"For N over its range, generate and show counts of the outputs of randN and unbiased(randN)". Missing the randN column}}
GP's random number generation is high-quality, using Brent's [http://maths.anu.edu.au/~brent/random.html XORGEN]. Thus this program is slow: the required 400,000 unbiased numbers generated through this bias/unbias scheme take nearly a second.
GP's random number generation is high-quality, using Brent's [http://maths.anu.edu.au/~brent/random.html XORGEN]. Thus this program is slow: the required 400,000 unbiased numbers generated through this bias/unbias scheme take nearly a second.
<lang parigp>randN(N)=!random(N);
<lang parigp>randN(N)=!random(N);
Line 664: Line 663:
)
)
};
};
for(n=3,6,print(n,"\t",sum(k=1,1e5,unbiased(n))))</lang>
for(n=3,6,print(n"\t"sum(k=1,1e5,unbiased(n))"\t"sum(k=1,1e5,randN(n))))</lang>


Output:
Output:
<pre>3 49913
<pre>3 49997 33540
4 49988 24714
4 49924
5 50143 20057
5 50240
6 50277</pre>
6 49913 16770</pre>


=={{header|Perl}}==
=={{header|Perl}}==