class Rooibos::Command::Random

A command that generates a random value.

Games roll dice. Encryption needs keys. Shuffling needs seeds. All of these call Kernel#rand or Random. But randomness in Update is a side effect: the same model and message would produce different results on each call. Testing would become fragile and non-deterministic.

This command delegates to Ruby’s Random class through the runtime. Update receives the result as a Message::Random.

Use it for dice rolls, shuffles, key generation, or any feature that needs random values without side effects in Update.

Prefer the Command.random factory method for convenience.

Example: Dice roll

def update(msg, model)
  case msg
  in { type: :random, envelope: :roll, value: }
    model.with(die_face: value)
  end
end

Example: Random float

def update(msg, model)
  case msg
  in { type: :random, envelope: :spawn_chance, value: }
    model.with(should_spawn: value < 0.3)
  end
end