class TrailGuide::Algorithms::Weighted
Public Instance Methods
choose!(**opts)
click to toggle source
# File lib/trail_guide/algorithms/weighted.rb, line 4 def choose!(**opts) reference = rand * variants.sum(&:weight) variants.each do |variant| return variant if variant.weight >= reference reference -= variant.weight end end