This gem add Enumerable#weighted_sample_by mehtod.
Add this line to your application's Gemfile:
gem 'weighted_sample'
And then execute:
$ bundle
Or install it yourself as:
$ gem install weighted_sample
[1, 9].weighted_sample_by {|x| x} => 9(90%) or 1(10%)
- Weight is zero or positive Integer(Negative or Float is not allowed).
- Sum of weights should > 0
- 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