Skip to content

lib:random

Experimental

Cryptographically secure random bytes, ints, strings, tokens, and UUIDs (v4 / v7).

PropertyValue
Namespacelib
Sourcesrc/lua/lib/random.rs
Teststests/lib/random.test.luau
StabilityExperimental
MirrorPython secrets + uuid; Node crypto

Syntax

lua
local rng = require("lib:random")

Description

WARNING

Stub. Full surface in module source; contract exercised by test file.

Reach for lib:random whenever the value needs to be unpredictable to an attacker — tokens, salts, IDs, nonces. Luau's built-in math.random is a seedable PRNG and is unfit for any of those uses.

Use uuid_v7 for database primary keys (timestamp-ordered → cheap B-tree inserts). Use uuid_v4 when ordering would leak information.

See also