weighted_sample
This gem add Enumerable#weighted_sample_by method.
Installation
Add this line to your application's Gemfile:
gem 'weighted_sample'
And then execute:
$ bundle
Or install it yourself as:
$ gem install weighted_sample
Usage
[1, 9].weighted_sample_by {|x| x}
#=> 9(90%) or 1(10%)Restrictions
- Weight is zero or positive Integer(Negative or Float is not allowed).
- Sum of weights should > 0
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Added some feature') - Push to the branch (
git push origin my-new-feature) - Create new Pull Request