Class: MonteCarlo::Simulator
- Inherits:
-
Object
- Object
- MonteCarlo::Simulator
- Defined in:
- lib/montecarlo/simulator.rb
Instance Method Summary collapse
-
#initialize(picker) ⇒ Simulator
constructor
A new instance of Simulator.
- #run(n_times = 1_000_000, threads = 1_000) ⇒ Object
Constructor Details
#initialize(picker) ⇒ Simulator
Returns a new instance of Simulator.
5 6 7 |
# File 'lib/montecarlo/simulator.rb', line 5 def initialize(picker) @picker = picker end |
Instance Method Details
#run(n_times = 1_000_000, threads = 1_000) ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/montecarlo/simulator.rb', line 9 def run(n_times = 1_000_000, threads = 1_000) picks = Parallel.map(1..n_times, in_threads: threads) do @picker.pick end picks.group_by { |pick| pick }.transform_values(&:size) end |