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}}==
<lang coffeescript>
biased_rand_function = (n) ->
Line 246 ⟶ 245:
console.log "ratio of 1s: #{cnt / sample_size} [#{label}]"
for n in [
console.log "\n---------- n = #{n}"
f_biased = biased_rand_function(n)
Line 256 ⟶ 255:
<lang>
> coffee unbiased.coffee
---------- n = 5
ratio of 1s: 0.
ratio of 1s: 0.
---------- n = 6
ratio of 1s: 0.
ratio of 1s: 0.
▲---------- 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]
</lang>
|