math_random
Returns a random decimal or a random value within the supplied bounds.
Target
Signature
1math_random(upper= ?, lower= ?)Returns a random decimal or a random value within the supplied bounds.
math_random is a global callable that can be used wherever an expression is valid. math_random is part of numeric expression work. Be deliberate about integer versus decimal inputs because several math helpers preserve or infer the result type from their arguments.
Parameters
upper- Optional value. Supply
upperpositionally unless the signature shows a keyword form. lower- Optional value. Supply
lowerpositionally unless the signature shows a keyword form.
Examples
Basic call
1math_random(10, 1)The positional upper bound comes before the lower bound.
Return a decimal between zero and one
1[2math_random()3]With no arguments the result is a decimal greater than or equal to zero and less than one.
Pick a random item from an array
1[2local(names) = array('Ada', 'Grace', 'Evelyn')3local(index) = integer(math_random(#names->size, 1))4#names->get(#index)5]The documented positional form takes the upper bound first and the lower bound second.
Use keyword bounds
1[2math_random(-upper=10, -lower=1)3]The keyword form names the bounds directly and returns an integer result.
Use decimal bounds
1[2math_random(1.0, 0.25)3]Decimal bounds produce a decimal result inside the requested range.
Application wrapper for lower-first readability
1[2define random_between(min::integer, max::integer) => math_random(#max, #min)3random_between(1, 10)4]Keep wrappers in application code so standard examples remain recognizable.