Module: RichEngine::Chance
- Defined in:
- lib/rich_engine/chance.rb
Overview
Random helpers for probability checks.
Class Method Summary collapse
-
.of(value, rand_gen: method(:rand)) ⇒ Boolean
Returns true with the given probability.
-
.of_one_in(value, rand_gen: method(:rand)) ⇒ Boolean
Returns true with a one-in-+value+ probability.
Class Method Details
.of(value, rand_gen: method(:rand)) ⇒ Boolean
Returns true with the given probability.
15 16 17 18 19 20 21 22 23 |
# File 'lib/rich_engine/chance.rb', line 15 def self.of(value, rand_gen: method(:rand)) percent = if value > 1 value / 100.0 else value end rand_gen.call < percent end |
.of_one_in(value, rand_gen: method(:rand)) ⇒ Boolean
Returns true with a one-in-+value+ probability.
32 33 34 |
# File 'lib/rich_engine/chance.rb', line 32 def self.of_one_in(value, rand_gen: method(:rand)) of(1 / value.to_f, rand_gen: rand_gen) end |