Skip to content

Instantly share code, notes, and snippets.

@howmanysmall
Last active April 1, 2022 17:19
Show Gist options
  • Save howmanysmall/e13d23555bc2a08083d39051f486527c to your computer and use it in GitHub Desktop.
Save howmanysmall/e13d23555bc2a08083d39051f486527c to your computer and use it in GitHub Desktop.
local CHARACTERS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz~`!@#$%^&*()-_=+[{]}\\|;:'\",<.>/?"
local RandomLib = Random.new(os.clock() % 1 * 1E7)
local function RandomString(Length)
local String = ""
for _ = Length, 0, -1 do
local Index = RandomLib:NextInteger(1, 94)
String ..= string.sub(CHARACTERS, Index, Index)
end
return String
end
-- StringBuffer version
local function RandomString(Length: number)
local String = table.create(Length)
for Index = 1, Length do
local CharacterIndex = RandomLib:NextInteger(1, 94)
String[Index] = string.sub(CHARACTERS, CharacterIndex, CharacterIndex)
end
return table.concat(String)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment