Skip to main content

random_element

Function random_element 

Source
pub fn random_element(
    set: &Value,
    ctx: Ctx,
    src: &mut dyn RandomSource,
) -> Result<Value, RandomError>
Expand description

RandomElement(S): a pseudo-random element of the finite set S (tlc2.module.TLC.RandomElement).

It draws exactly as TLC does, so with a JavaRandom stream seeded as TLC seeds it, the result is TLC’s:

  • [D -> R]: one RandomElement(R) per element of D, in normalized order;
  • [f1 : S1, ...]: one per field, in TLC’s field order;
  • S1 \X ... \X Sn: one per component;
  • a..b: a + floor(nextDouble() * (b - a + 1));
  • any other finite set: element floor(nextDouble() * |S|) of its normalized enumeration.

§Errors

TLC’s: TLC_MODULE_APPLYING_TO_WRONG_VALUE for a non-set or an infinite set, and TLC_MODULE_VALUE_JAVA_METHOD_OVERRIDE for an empty set (after a draw, as in TLC) and for enumeration errors.