Class: EenieMeenie::Sorters::PureRandom
- Defined in:
- lib/eenie_meenie/sorters/pure_random.rb,
lib/eenie_meenie/sorters/bucket_shuffle.rb
Instance Method Summary collapse
-
#initialize(*args, options) ⇒ PureRandom
constructor
A new instance of PureRandom.
- #sort ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(*args, options) ⇒ PureRandom
Returns a new instance of PureRandom.
4 5 6 |
# File 'lib/eenie_meenie/sorters/pure_random.rb', line 4 def initialize(*args, ) (:groups, :population, ) end |
Instance Method Details
#sort ⇒ Object
8 9 10 11 12 13 14 15 16 |
# File 'lib/eenie_meenie/sorters/pure_random.rb', line 8 def sort results = {} @groups.each { |group| results.merge!(group => 0) } @population.times do |i| results[(rand(@population) > (@population / 2) ? @groups.first : @groups.last)] += 1 end groups = results end |