String

Library
Updated 2 months ago · v1.3.7
i

Shared Module — extends the global string table

string.random

Generates a random string based on a pattern.

lua
local serial = string.random('1111-AAAA-aaaa') -- e.g. "4827-KFMZ-pqxl"
local code = string.random('AAA-111')           -- e.g. "XKR-482"
ParameterTypeRequiredDescription
patternstringyesPattern string (see characters below)
lengthintegernoPad or truncate result to this length

Pattern Characters

CharGenerates
1Random digit (0–9)
ARandom uppercase letter (A–Z)
aRandom lowercase letter (a–z)
.Random alphanumeric character
^Next character is treated as a literal
anything elsePassed through as-is

Examples

lua
string.random('11-AAA')       -- "47-QKM"
string.random('^1111')        -- "1423" (first '1' literal via ^, rest random)
string.random('....-....')    -- "k4Rz-9xBm"
Was this page helpful?
This page was last updated on 12 March 2026
DIRKSCRIPTS
All you need for your FiveM server.10% off your first order

Unsubscribe any time.

Copyright © 2026 DirkScripts. Not affiliated with or endorsed by Rockstar North or Take-Two Interactive.