Module: WeightedRandom::ClassMethods
- Defined in:
- lib/weighted_random.rb
Instance Method Summary collapse
Instance Method Details
#weighted_rand ⇒ Object
13 14 15 |
# File 'lib/weighted_random.rb', line 13 def weighted_rand self.where("cumulative_weight > #{Kernel.rand(self.maximum('cumulative_weight'))}").order('cumulative_weight').limit(1).first end |