Unbias a random generator: Difference between revisions
Content added Content deleted
(→{{header|Ruby}}: added comments to code.) |
m (→{{header|Ruby}}: removed a space) |
||
Line 1,290: | Line 1,290: | ||
counter = Hash.new(0) # counter will respond with 0 when key is not known |
counter = Hash.new(0) # counter will respond with 0 when key is not known |
||
runs.times do |
runs.times do |
||
counter[:biased] += 1 if rand_n(bias) == 1 #the first time, counter has no key for : |
counter[:biased] += 1 if rand_n(bias) == 1 #the first time, counter has no key for :biased, so it will respond 0 |
||
counter[:unbiased] += 1 if unbiased(bias) == 1 |
counter[:unbiased] += 1 if unbiased(bias) == 1 |
||
end |
end |