Created
August 8, 2019 12:56
-
-
Save ChaunceyHoover/6e0ba8a18115517ffce39fca86a1e8db to your computer and use it in GitHub Desktop.
Simple lua string generator
This file contains 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
function rand_str(len) | |
len = tonumber(len) or 1 | |
local function rand_char() | |
return math.random() > 0.5 | |
and string.char(math.random(65, 90)) | |
or string.char(math.random(97, 122)) | |
end | |
local function rand_num() | |
return string.char(math.random(48, 57)) | |
end | |
local str = "" | |
for i = 1, len do | |
str = str .. (math.random() > 0.5 and rand_char() or rand_num()) | |
end | |
return str | |
end | |
--print(rand_str(10)) => 10 random alphanumeric characters |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just importing old pastebin scripts to my gist