Class: BoxMuller::Distributor

Inherits:
Object
  • Object
show all
Defined in:
lib/box_muller/distributor.rb

Instance Method Summary collapse

Constructor Details

#initializeDistributor

Returns a new instance of Distributor.



3
4
# File 'lib/box_muller/distributor.rb', line 3

def initialize
end

Instance Method Details

#distribute(total:, count:, variance: 10.0) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/box_muller/distributor.rb', line 6

def distribute(total:, count:, variance: 10.0)
  tmp_total = total
  count.times.map { |i|
    if i == count - 1 # reaches the last item
      tmp_total
    else
      current = gaussian(mean: tmp_total / (count - i), variance: variance).first.round
      tmp_total = tmp_total - current
      current
    end
  }
end