Class: EenieMeenie::Sorters::PureRandom
- Inherits:
-
Base
- Object
- Base
- EenieMeenie::Sorters::PureRandom
show all
- Defined in:
- lib/eenie_meenie/sorters/pure_random.rb,
lib/eenie_meenie/sorters/bucket_shuffle.rb
Instance Method Summary
collapse
Methods inherited from Base
#load_option, #load_options
Constructor Details
#initialize(*args, options) ⇒ PureRandom
4
5
6
|
# File 'lib/eenie_meenie/sorters/pure_random.rb', line 4
def initialize(*args, options)
load_options(:groups, :population, options)
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
|