Unbias a random generator: Difference between revisions

Content added Content deleted
(→‎{{header|CoffeeScript}}: Range of N is wrong)
(use proper range)
Line 221:
 
=={{header|CoffeeScript}}==
{{incomplete|CoffeeScript|range of N is 3..6 not 5..9}}
<lang coffeescript>
biased_rand_function = (n) ->
Line 246 ⟶ 245:
console.log "ratio of 1s: #{cnt / sample_size} [#{label}]"
for n in [53..96]
console.log "\n---------- n = #{n}"
f_biased = biased_rand_function(n)
Line 256 ⟶ 255:
<lang>
> coffee unbiased.coffee
 
---------- n = 73
ratio of 1s: 0.14298043333343 [biased]
ratio of 1s: 0.50004024999514 [unbiased]
 
---------- n = 84
ratio of 1s: 0.12498472499751 [biased]
ratio of 1s: 0.5002794998067 [unbiased]
 
---------- n = 5
ratio of 1s: 0.1999817199729 [biased]
ratio of 1s: 0.49989295003183 [unbiased]
 
---------- n = 6
ratio of 1s: 0.16662721664843 [biased]
ratio of 1s: 0.49994314997813 [unbiased]
 
---------- n = 7
ratio of 1s: 0.1429804 [biased]
ratio of 1s: 0.5000402 [unbiased]
 
---------- n = 8
ratio of 1s: 0.1249847 [biased]
ratio of 1s: 0.500279 [unbiased]
 
---------- n = 9
ratio of 1s: 0.1110524 [biased]
ratio of 1s: 0.4999337 [unbiased]
</lang>