Unbias a random generator: Difference between revisions

GP
(GP)
Line 243:
unbias 49820 50180 49.82 50.18
</pre>
 
=={{header|PARI/GP}}==
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);
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))))</lang>
 
=={{header|PicoLisp}}==
Line 272 ⟶ 285:
5: 20.04 % 49.75 %
6: 16.32 % 49.02 %</pre>
 
=={{header|PureBasic}}==
<lang PureBasic>Procedure biased(n)