An extension to the Fisher-Yates-Shuffle algorithm to support weights. It includes a ruby core extension convenience of arrays.
Add this line to your application's Gemfile:
gem 'weighted_shuffle'
And then execute:
$ bundle
Or install it yourself as:
$ gem install weighted_shuffle
standalone usage:
array = [[:a, 1], [:b, 2]] # 1, 2 are weights
dealer = WeightedShuffle::Dealer.new array
dealer.weighted_shuffle
=> [:b, :a]
integrated into ruby Array:
require 'weighted_shuffle/core_ext/array/weighted_shuffle'
array = [[:a, 1], [:b, 2]]
array.weighted_shuffle
=> [:b, :a]
or with factor
array.weighted_shuffle factor: 3
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request