Last active
April 1, 2022 17:19
-
-
Save howmanysmall/e13d23555bc2a08083d39051f486527c to your computer and use it in GitHub Desktop.
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
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