Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make a Random Name Generator?

Asked by
len_ny 8
6 years ago

Example of what I want it to do: z24j2ksahj2190!**@#jnkasjk!*n238

How do i make a script that names itself something like that but shorter?

2 answers

Log in to vote
1
Answered by 6 years ago

If you want to generate a random string, firstly create an array with all of the characters you want to include:

Characters = {"a", "b", "c", "d", "e", "f", "g" -- and so on... }

Then select a random number with the range of the length of your array:

RandomNumber = math.random(#Characters) -- The #Characters gets the length of the array.

Now index this random number to select a random item in the array and concatenate (join together) this into a string variable.

String = ""

for i=1, 10 do -- The number 10 is how long you want the string to be.
    String = String..Characters[RandomNumber]
end

print(String)

Please excuse any errors, as I made this up on the spot. I may have misinterpreted the question, but I hope this helps.

0
ill try it out looks like it would work as expected though! len_ny 8 — 6y
0
You could use "string.char(math.random(34, 122))" instead of a character table to make it shorter. Otherwise, good answer! hiimgoodpack 2009 — 6y
0
Please accept my answer if it helped! shadow7692 69 — 6y
Ad
Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

i know im like 3 years late but for anyone looking for this i did this:

function randomstring()
    local length = math.random(10,20)
    local array = {}
    for i = 1,length do
        array[i] = string.char(math.random(32,126))
    end
    return table.concat(array)
end

if you would want to use it, write the function and then do (instance).Name For example,

function randomstring()
    local length = math.random(10,20)
    local array = {}
    for i = 1,length do
        array[i] = string.char(math.random(32,126))
    end
    return table.concat(array)
end

script.Name = randomstring()

and the script name would be something like "|_x^f6`I@'^v5I;<00VW"

Answer this question