Created
August 4, 2017 13:32
-
-
Save sunfarm/b78736dc15e74e461030d09f1d0b6045 to your computer and use it in GitHub Desktop.
Generate a pseudo-random string in Lua
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
-- Generate a pseudo-random string | |
-- If this is run more than once in the same second given by os.time(), it will generate the same string | |
local chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_+-={}|[]`~' | |
local length = 40 | |
local randomString = '' | |
math.randomseed(os.time()) | |
charTable = {} | |
for c in chars:gmatch"." do | |
table.insert(charTable, c) | |
end | |
for i = 1, length do | |
randomString = randomString .. charTable[math.random(1, #charTable)] | |
end | |
print(randomString) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Wow thank you!