Elpho LogoElpho

math module

Deterministic math helpers for rolls, ranges, and scaling. All synchronous.

Overview

Use math for random numbers, rounding, clamping, and mapping one range into another. Good for games and cooldowns.

API

  • random() (0-1), floor, ceil, round.
  • clamp(value, min, max).
  • mapRange(value, inMin, inMax, outMin, outMax).
Randomness is sandboxed and not seedable.

Examples

javascript
const math = use("math");
function main() {
const roll = math.floor(math.random() * 6) + 1;
ctx.reply("You rolled a d6: " + roll);
}
javascript
const math = use("math");
function main() {
const pct = 73;
const bar = math.mapRange(pct, 0, 100, 0, 10);
const filled = math.round(bar);
ctx.reply("Progress: [" + "#".repeat(filled) + "-".repeat(10 - filled) + "]");
}