module Simulation

The code to run n monte carlo simulations args is a hash that must contain the following: :backlog :split_factor :runs :low :high

Constants

PERCENTILES

Public Instance Methods

percentiles(options) click to toggle source
# File lib/monte/simulation.rb, line 13
def percentiles(options)
  results = run_simulations(options).sort
  PERCENTILES.map do |percentile|
    index = options[:runs] * (percentile - 1)
    results[index]
  end
end
run_simulations(options) click to toggle source
# File lib/monte/simulation.rb, line 21
def run_simulations(options)
  estimated_backlog = options[:backlog] * options[:split]
  Array.new(options[:runs]) do |_|
    options[:start] + simulate(
      estimated_backlog,
      options[:throughput]
    ) * 7
  end
end
simulate(backlog, throughput, result = 0) click to toggle source
# File lib/monte/simulation.rb, line 31
def simulate(backlog, throughput, result = 0)
  return result if backlog <= 0

  simulate(
    backlog - throughput.sample,
    throughput,
    result + 1
  )
end