glemy/random
Deterministic-given-input random selection – a genre-agnostic Core
utility, not part of glemy/physics (physics and randomness are
separate concerns in every engine surveyed: Bevy’s bevy_rand,
Godot’s RandomNumberGenerator, and LÖVE2D’s love.math all live
apart from their respective physics modules).
Values
pub fn pick(random: Float, options: List(a)) -> Result(a, Nil)
Picks one element of options, given random – a float expected to
be in [0.0, 1.0) (e.g. float.random()’s own documented range).
Takes random as a plain argument rather than generating it
internally, so callers stay pure and deterministic-given-input –
this is what a second, genre-distinct game’s own random mechanics
would need too, and matches Godot’s own confirmed
seeded-RNG-non-reproducibility problem across engine versions
(godot/godot#27856) as a reason to never let a Core utility own its
own random state.
Error(Nil) on an empty options – callers decide their own
fallback (see glemy/games/tiers/rules.random_droppable, which falls
back to tier 0).
pick(0.0, [0, 1, 2])
// -> Ok(0)
pick(0.99, [0, 1, 2])
// -> Ok(2)
pick(0.5, [])
// -> Error(Nil)