Unbias a random generator: Difference between revisions

m
moved R to after Quackery
(Added Quackery.)
m (moved R to after Quackery)
Line 1,620:
Unbiased = Stats(count1=499963, count0=500037, percent=49.996299999999998)</pre>
 
=={{header|RQuackery}}==
 
<lang rsplus>randN = function(N) sample.int(N, 1) == 1
 
unbiased = function(f)
{while ((x <- f()) == f()) {}
x}
 
samples = 10000
print(t(round(d = 2, sapply(3:6, function(N) c(
N = N,
biased = mean(replicate(samples, randN(N))),
unbiased = mean(replicate(samples, unbiased(function() randN(N)))))))))</lang>
 
Sample output:
 
<pre> N biased unbiased
[1,] 3 0.32 0.50
[2,] 4 0.24 0.50
[3,] 5 0.21 0.49
[4,] 6 0.16 0.51</pre>
 
=={{header|Quackery}}==
 
<lang Quackery> $ "bigrat.qky" loadfile
Line 1,687 ⟶ 1,665:
</pre>
 
 
 
=={{header|QuackeryR}}==
 
<lang rsplus>randN = function(N) sample.int(N, 1) == 1
 
unbiased = function(f)
{while ((x <- f()) == f()) {}
x}
 
samples = 10000
print(t(round(d = 2, sapply(3:6, function(N) c(
N = N,
biased = mean(replicate(samples, randN(N))),
unbiased = mean(replicate(samples, unbiased(function() randN(N)))))))))</lang>
 
Sample output:
 
<pre> N biased unbiased
[1,] 3 0.32 0.50
[2,] 4 0.24 0.50
[3,] 5 0.21 0.49
[4,] 6 0.16 0.51</pre>
 
=={{header|Racket}}==
1,462

edits