Tiempo y random
-- Doc example: time & random. `time` is auto-granted; `random` is NOT (deny-by-default).
intent: "doc example: time and random"
require random
print("epoch 0 = " + format_time(0) + ", a die roll = " + text(random_int(1, 6)))
test "format_time / parse_time round-trip (UTC, ISO-8601)"
assert_eq(format_time(0), "1970-01-01T00:00:00Z")
assert_eq(parse_time("1970-01-01T00:00:00Z"), 0)
assert(now() > 1000000000)
test "random needs `require random`; values land in range"
let r be random()
assert(r >= 0 and r < 1)
let d be random_int(1, 6)
assert(d >= 1 and d <= 6)
Tiempo
time se auto-otorga bajo run/test (declarás require time bajo serve).
now() -- timestamp unix (number)
format_time(now()) -- ISO-8601 UTC por defecto
format_time(t, "%Y-%m-%d %H:%M") -- patrón strftime
parse_time("2026-06-30T12:00:00Z") -- inverso de format_time
sleep(segundos) -- pausa
Random — deny-by-default
A diferencia de muchos lenguajes, random necesita require random incluso bajo run — porque la aleatoriedad se usa para tokens y nonces, es una capacidad, no algo gratis.
require random
random() -- float en [0, 1)
random_int(1, 6) -- entero en [min, max]