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
7 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 7 years ago

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

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

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

1RandomNumber = 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.

1String = ""
2 
3for i=1, 10 do -- The number 10 is how long you want the string to be.
4    String = String..Characters[RandomNumber]
5end
6 
7print(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 — 7y
0
You could use "string.char(math.random(34, 122))" instead of a character table to make it shorter. Otherwise, good answer! hiimgoodpack 2009 — 7y
0
Please accept my answer if it helped! shadow7692 69 — 7y
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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

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

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

01function randomstring()
02    local length = math.random(10,20)
03    local array = {}
04    for i = 1,length do
05        array[i] = string.char(math.random(32,126))
06    end
07    return table.concat(array)
08end
09 
10script.Name = randomstring()

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

Answer this question