DirkScripts
Docs
String
βΉοΈ Shared Module β extends the global string table
#string.random
Generates a random string based on a pattern.
lualocal serial = string.random('1111-AAAA-aaaa') -- e.g. "4827-KFMZ-pqxl" local code = string.random('AAA-111') -- e.g. "XKR-482"
| Parameter | Type | Required | Description |
|---|---|---|---|
| pattern | string | yes | Pattern string (see characters below) |
| length | integer | no | Pad or truncate result to this length |
#Pattern Characters
| Char | Generates |
|---|---|
1 | Random digit (0β9) |
A | Random uppercase letter (AβZ) |
a | Random lowercase letter (aβz) |
. | Random alphanumeric character |
^ | Next character is treated as a literal |
| anything else | Passed through as-is |
#Examples
luastring.random('11-AAA') -- "47-QKM" string.random('^1111') -- "1423" (first '1' literal via ^, rest random) string.random('....-....') -- "k4Rz-9xBm"
