Skip to content

Instantly share code, notes, and snippets.

@sunfarm
Created August 4, 2017 13:32
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sunfarm/b78736dc15e74e461030d09f1d0b6045 to your computer and use it in GitHub Desktop.
Save sunfarm/b78736dc15e74e461030d09f1d0b6045 to your computer and use it in GitHub Desktop.
Generate a pseudo-random string in Lua
-- 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)
@anton2007
Copy link

Wow thank you!

@023948799e213e21b53eb83785356208

Thx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment