Sha256: fe199d4475d4615d117d4a774c50a76234807ac01caba15719231697dde73ef4
Contents?: true
Size: 379 Bytes
Versions: 20
Compression:
Stored size: 379 Bytes
Contents
module Split module Algorithms module WeightedSample def self.choose_alternative(experiment) weights = experiment.alternatives.map(&:weight) total = weights.inject(:+) point = rand * total experiment.alternatives.zip(weights).each do |n,w| return n if w >= point point -= w end end end end end
Version data entries
20 entries across 20 versions & 1 rubygems