Reference · General
random
random() -> floatWhat it does
A float from 0 up to, but not including, 1, different on each call. It is fast and predictable, so it serves games, sampling and jitter, not secrets: a session id or a token comes from uuid or crypto.token. There is no seed, so runs are not repeatable.
Examples
let r = random()print(type_of(r), r >= 0.0, r < 1.0)print(random() != random())float true truetrueEdge cases
- The result is always a float, even when it happens to be whole; scale and truncate for an int, or use random_int, which includes both ends.
- Two calls in one expression are two different numbers; a list made with
maphas a fresh one per item. random()takes no arguments; one given is a runtime error (below).
print(type_of(floor(random() * 10)), int(random() * 10) >= 0)print(range(5) | map((i) => random()) | unique | len)int true5Errors
random never fails and never gives an error value. An argument is a runtime error,
and so is one for quillo check when the call is written out.
print(is_err(random()))falseprint(random(1))line 1: `random` takes 0 arguments, got 1: random()Chaining
random starts a pipeline rather than taking one, since it has no argument.
print(random() * 100 | floor | type_of)print(["a", "b", "c"] | map((x) => random()) | len)int3See also
random_int, uuid, crypto.token, floor
Thread 0 posts
On random(): questions, tips, corrections, and code that uses it.
No posts yet. The first one opens the thread.
Edit this page on GitHub · every example's output was made by running it (tools/refcheck.mjs) · questions on Discord or r/quillo