Sha256: 3b5b3b99852901458982be88693d7376ec36211dd3c08e719c8ff17735c550ae
Contents?: true
Size: 757 Bytes
Versions: 1
Compression:
Stored size: 757 Bytes
Contents
# Weighted selection Simple weighted selection of items ## Installation Install [RAKE](https://rubygems.org/gems/weighted-selection) via RubyGem: ``` gem install weighted-selection ``` ## Usage Import the library and create a new instance ``` require 'weighted_selection' sel = WeightedSelection::Engine.new ``` ## Add items Add single items to the selecter ``` sel.add_item(WeightedSelection::Item.new('Item 1', 25) sel.add_item(WeightedSelection::Item.new('Item 2', 25) ``` Or multiple at once ``` sel.add_items([ WeightedSelection::Item.new('Item 3', 25), WeightedSelection::Item.new('Item 4', 25) ]) ``` ## Fetch a sample Fetch a sample based on the item's weights ``` sel.select ``` Or multiple at once ``` sel.multiple(100) ```
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
weighted-selection-1.0.0 | README.md |