Random String Generator

For some reason, Roblox doesnโ€™t allow you to generate a random string without using a script. To save you some time, I have created one for you:

Example:

local module = require(script.RandomStringGen)
local key = module.Stringify(20, 3)
print(key)

Explanation:

This module consists of two parts:

  1. The first integer value specifies the desired length of the string (in this case, it is set to 20).

  2. The second integer value determines the composition of the string. Here are the available options:
    1 = Uppercase letters only
    2 = Uppercase and lowercase letters only
    3 = Uppercase letters, lowercase letters, and numbers

Thatโ€™s all! Please let me know if you encounter any issues or have any suggestions.

Link: RandomStringGen - Roblox

This is my first time making a post like this so please leave constructive criticism

13 Likes

What is the use case for this?

5 Likes

I personally use it as a Discord to Roblox verifier (kinda like bloxlink.) Itโ€™s extremally useful for generating one-time keys.

2 Likes

sometimes you just make things for fun :man_shrugging:

9 Likes

Just by looking at the source code, this is a lot longer than it has to be. Realistically, itโ€™s as simple as this:

local ValidCharacters = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}
local String = ``
for i = 1, len do
	String = String..ValidCharacters[math.random(1,#ValidCharacters)]
end
4 Likes

very true, I should probably update my random generator to use this as well.

3 Likes

I have shortened this resource down to two lines of code:

local http = game:FindService("HttpService")
local str = http:GenerateGUID()
4 Likes

To be fair, I implemented a couple other features; but I completely get your point. I got the letters using their ASCII values because for some reason my brain at 4am thought itโ€™d be way simpler than actually typing each character out one by one.

I didnโ€™t even know that existed, damn.

string.split it. Dont type that all out in a table :sob:

1 Like

Actually, the best option is to use string:sub.

Why not utilize math.random() and pass the resulting number into the string.char() method instead of manually typing out all possible characters?

1 Like

Alternatively you could just do

local String = ""

for _ = 0, Length do
   String = String .. string.char(math.random(97, 122))
end
2 Likes

My face when

local RandomString = (function() local t = {}; for i = 0, math.random(0, 1000) do table.insert(t, utf8.char(math.random(1, 1114111))) end; return table.concat(t, ""); end)()

warn(RandomString) --> ๒Žณƒ๓„›ˆ๑ฌ—Œ๑’ฅบ๔‰ž•๑—พฎ๑ƒŠ’๒ฝˆ๓—ปฒ๓ซŽน๐จƒ‡๓ฐ„ฉ๎…ซ๐ปฟŸ๓’›๓“ดธ๒ณขฏ๑Œบ—๐ ๓Œฑฌ๐ฉ“ฑ๔†๐ฃœœ๓ด—ฝ๑Žฒ‘ๆšŠ๓พ ˜๒ฐฐ๒งฉฒ๑…ฆณ๓ช’๑ฟณœ๐“Šจ๑Žฐˆ๒€ฉข๐–ƒ˜๒ถ›…๐œฐฒ๒Žข˜๒พŠ’๓คฉ–๑ฃชง๔ƒก“๓‚œฌ๐ฃŸ๓ฐŽฟ๓š€น๐ซกฌ๔‚ฅ™๒ผฃ†๑ฒธธ๑ทฑ…๒น‰ก๒กฟฆ๒ณฑ‘็ˆˆ๒ตž๔‡ท๐•œ๒ƒฏบ๒–ชœ๑นš๑ง›ผ๓”‘ป๒œงฌไ๒›€Ž๒ƒถฒ๐ฏฝ›๒ค€๒ฌซ…๔„๓Šจฎ๒ˆŸŸ๐ฅฏช๒ชš˜๑žตš๒ฝด’๑Ž—๑ƒฃป๓ซง‡๐Ÿ’ƒๅธ“๒–ด๓ทนŒ๒ท—ถ๒ซฐ๐“‹€๒ถถก๐ฅค๓ž’๑ฃฌ๑ฎžก๎€Š๑Ÿญ•๒ฎ๔‰–ถ๎ซ—๒ผ›Œ๓ตฅค๑†ˆธ๓พฆถ๐ฆผค๐ค›๒€‰ฃ๐ฒฝข๔†™โท’๑ปณ‹๓‘’„๓งช‡๐ณปน๐š‚Ÿ๒‰—„๑Šฎซ๑ฑต‰๓จฆ๓ŽŽฎ๑›นง๓ชค–๐ญœ”๓ป†๓ขฆฟ๐ž”‚๑˜›ก๐š„ป็ ฎ๒„จน๐จงธ๒–๓ก‰”แŠš๒Žƒ„๒“บ๑ฅ†ฝ๒†ƒธ๑‹Ÿค๒šฏ’๑Ÿ—๒ผซธ๑ณŒ๓งขŒ๐››ฝ๐ฑ††๑’ง๒บŠ๔…˜ฌ๓ณบ‰๓‘„€๐ณ€™๓ป‚ฒั–๓ธฑ๑บจผ๓‹ซท๑ƒจœ๑ธ…‡๒ ตฟ๐ฑŽ†๒คงบ๏Šˆ๑ง…๔‚ฉ’๒“ง“๑ปˆ๐ธ๒žธฝ๓—ด๑ƒ„๐ป–บ๔†™–๋€•๒นซพ๒’ดษƒ๐งฟ”๑Œ›ใ’๑››‰๓“Žด๒ญ„ป๓ฝ†ต๑ฃผข๑Šข‘๑“œ๔Šš๑ผน๓†๒…ฑš๓…ทต๑…‹’๑ฟฉณ๐ฏซ๒ซฑ๒•‚๓‰šช๓…ฐฟ๑”จ๒ฝข๓’ฅ

Readable code be like

local randomString = game:GetService("HttpService"):GenerateGUID()

This is a GUID, not a random string since it has the {} and dashes (i forgot the name mbmb)

if you want a TRULY random string, use the utf8 library

local randomString = string.gsub(game:GetService("HttpService"):GenerateGUID(false), "-", "")

2 Likes

As I said, it isnโ€™t truly random as it only uses letters and numbers

What you are showing me is called an UUID

You donโ€™t really have a random string. Though a UUID for keys is great!
But for a truly random string, utf8 has WAYYYY MORE CHARACTERS than a GUID.

That is technically three lines. Iโ€™m assuming that is a unicode random generator.

This seems very useful for procedural tags and such, Iโ€™ll probably be using this for future projects.

1 Like