Random

Source: standard-library. Raw markdown: /raw/docs/standard-library/4-plugins/random.md

Random

The random plugin provides pseudo-random generators for decimal, integer, bool, and string values. Each vibration key maps to a random processing function. Invalid inputs are logged and result in no vibration.

Functions


decimal

Generates random decimal in [0, max) for scalar max, or [min, max) for array input. The upper bound is exclusive.

10  random.decimal ? // 4.2719

Invalid decimal input no vibration will happen.

"bad"  random.decimal ? // no vibration
  • Type: ERROR
  • Code: INVALID_DECIMAL_INPUT
  • Message: Decimal random expects a number or [min,max] range.

integer

Generates random integer in [0, max] for scalar max, or [min, max] for array input. Both bounds are inclusive.

(1,6)  random.integer ? // 4

Invalid integer input no vibration will happen.

"x"  random.integer ? // no vibration
  • Type: ERROR
  • Code: INVALID_INTEGER_INPUT
  • Message: Integer random expects a number or [min,max] range.

bool

Generates random boolean using default 0.5 true probability.

random.bool ? // true

Input value is ignored for bool generation.

"anything"  random.bool ? // false

string

Generates random alphanumeric string of requested length.

12  random.string ? // "aB9xQ2mN7pL1"

Negative or invalid length results in no vibration due to conversion failure.

"bad"  random.string ? // no vibration
  • Type: ERROR
  • Code: INVALID_STRING_LENGTH
  • Message: String random expects a valid non-negative length value.