Random choose by chance

inspired by https://stackoverflow.com/questions/19261061/picking-a-random-option-where-each-option-has-a-different-probability-of-being/19265735

use Hash

{noteA => chanceA, noteB => chanceB, noteC => chanceC}

random choose note by chance

def picker(options)
  current, max = 0, options.values.inject(:+)
  random_value = rrand(0,max)
  options.each do |key,val|
    current += val
    return key if random_value <= current
  end
end

opti = {:C4=>1, :D4=>2, :E4=>3 }
9.times do
  play picker(opti)
  sleep 0.25
end

random_value should use rrand(0,max), not rand(max)+1