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

cant use math.random how do i make it do this?

Asked by
aindev 4
5 years ago

local var1 = math.random(a,z),(0,9) local var2 = math.random(_),(0,9) local var3 = math.random(a,z),(0,9)

print(var1..var2..var3)

i need var1 to choose a random number or letter var2 is an underscore or a number var3 is a letter or number

0
math.random only takes in 2 values so math.random(MinNumber,MaxNumber) LostPast 253 — 5y
0
Please code block your code using the Lua button in the message editor. xAtom_ik 574 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago

If you wanted something to be a letter or number you could have a math.random(0,35)

If the number is anywhere from 0-9 then set it equal to value (a number), else subtract 9 from the value and have an alphabet table like this...

local alphabet = { "a", "b", "c", "d", ... }

Where if you would get a random letter by doing alphabet[value] (a letter).

0
The built in function "string.char(...)" does this in a slightly nicer way. string.byte("a") gives the alphanumerical code of "a". So, `string.char(math.random(string.byte("a"), string.byte("z")))` should be what you want fredfishy 833 — 5y
Ad

Answer this question