Reference · General

random

signature
random() -> float

What 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())
output
float true truetrue

Edge cases

print(type_of(floor(random() * 10)), int(random() * 10) >= 0)print(range(5) | map((i) => random()) | unique | len)
output
int true5

Errors

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()))
output
false
this one fails
print(random(1))
output
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)
output
int3

See also

random_int, uuid, crypto.token, floor

Thread
8Useful? Like it, or add to its thread below.

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