Q&A / math

Why does math_random take the upper bound first?

The positional form feels backwards. What should portable code do?

Accepted answer by accepted-answer

Use the documented order. In the positional form, the upper bound is supplied first and the lower bound second.
1math_random(10, 1)
Do not silently swap values in a general-purpose compatibility helper.

Answer by wrapper-answer

If your application prefers lower-first readability, create a clearly named application helper.
1define random_between(min::integer, max::integer) => math_random(#max, #min)
Keep the wrapper in application code so standard examples stay recognizable.

Related manual category