Class: Synthra::Generator::Modes::MixedMode
- Defined in:
- lib/synthra/generator/modes.rb
Overview
Mixed mode - combination of random, edge, and invalid
Probabilistically mixes all three modes according to specified ratios. Default: 80% random, 15% edge, 5% invalid.
Constant Summary collapse
- DEFAULT_RATIOS =
Default mode ratios
{ random: 80, edge: 15, invalid: 5 }.freeze
Instance Method Summary collapse
-
#generate(type_instance, args, context = nil) ⇒ Object
Generate a value using mixed mode.
-
#initialize(rng, ratios: DEFAULT_RATIOS) ⇒ MixedMode
constructor
Create a new MixedMode instance.
Constructor Details
#initialize(rng, ratios: DEFAULT_RATIOS) ⇒ MixedMode
Create a new MixedMode instance
287 288 289 290 291 292 293 |
# File 'lib/synthra/generator/modes.rb', line 287 def initialize(rng, ratios: DEFAULT_RATIOS) super(rng) @ratios = ratios @random_mode = RandomMode.new(rng) @edge_mode = EdgeMode.new(rng) @invalid_mode = InvalidMode.new(rng) end |
Instance Method Details
#generate(type_instance, args, context = nil) ⇒ Object
Generate a value using mixed mode
Selects a mode probabilistically based on ratios and generates a value using that mode.
306 307 308 309 310 311 312 313 314 315 316 317 318 |
# File 'lib/synthra/generator/modes.rb', line 306 def generate(type_instance, args, context = nil) context ||= Generator::Context.new roll = @rng.rand(100) cumulative = 0 if roll < (cumulative += @ratios[:random]) @random_mode.generate(type_instance, args, context) elsif roll < (cumulative += @ratios[:edge]) @edge_mode.generate(type_instance, args, context) else @invalid_mode.generate(type_instance, args, context) end end |