Last active
June 30, 2024 02:30
-
-
Save haggen/2fd643ea9a261fea2094 to your computer and use it in GitHub Desktop.
Random strings in Lua
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
math.randomseed(os.time()) | |
local charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890" | |
function string.random(length) | |
if length > 0 then | |
return string.random(length - 1) .. charset:sub(math.random(1, #charset), 1) | |
else | |
return "" | |
end | |
end |
wavesk
commented
Jul 31, 2023
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment