A tiny, URL-friendly, unique string ID generator for Roblox (Luau).
This package is a Roblox implementation of Nano ID, the original project by Andrey Sitnik: https://github.com/ai/nanoid
- Short IDs: uses the URL-safe alphabet (
A-Za-z0-9_-) style with a compact default size. - Simple API: one function to generate IDs.
- Customizable: supports custom size and custom alphabet.
Like the original Nano ID approach, this implementation generates IDs by:
- Choosing an alphabet (default: URL-friendly symbols).
- Picking random characters from that alphabet.
- Repeating until the target length is reached (default:
21).
The original Nano ID emphasizes cryptographic randomness.
In this Roblox version, randomness comes from Random.new().
If you need strict cryptographic guarantees, review your platform constraints and threat model before using generated IDs for security-sensitive use cases.
- Default ID size:
21 - Default alphabet: URL-friendly Nano ID alphabet
Collision probability depends on:
- Alphabet length
- ID size
- Total number of generated IDs
Larger alphabets and longer IDs reduce collision risk.
[dependencies]
nanoid = "stackyzdev/nanoid@0.1.0"local nanoid = require(path.to.nanoid)
local id = nanoid()
print(id) -- e.g. V1StGXR8_Z5jdHi6B-myT
local shortId = nanoid(10)
print(shortId)
local custom = nanoid(12, "1234567890abcdef")
print(custom)generate(size: number?, alphabet: string?) -> stringsize(optional): target length of the ID (default:21)alphabet(optional): characters used to build the ID
- Original Nano ID by Andrey Sitnik and contributors: https://github.com/ai/nanoid