Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Randomize only 2 numbers instead of Number-Number? [SOLVED]

Using;

math.random(1-3)

Would give you an output of;

1,2, or3

How would I make it so it only does two number giving an output of;

1 or 3 only

I am trying to randomize L and N by doing this:

for i = 1, 6 do
	W = W..string.char(math.random(76,78))
end

But it gives me L,M, andN I only want it to give me LandN

1 answer

✓ Accepted answer

Well, what you can do is use math.random() to get either 1 or 2 and set the actual value based off that.

So for example:

w = ""
for i = 1,6 do
local ran = math.random(1,2)
local char = (ran==1 and 76 or 78)
w=w..string.char(char)
end

If you are confused about this line:

local char = (ran==1 and 76 or 78)

It is exactly the same as:

if ran ==1 then
char = 76
else
char = 78
end

That is what is called a conditional ternary operator.

1 comment

0

I wasn't confused. But thanks for the help! I can't believe I didn't think of that.

This discussion is preserved as it was. New answers, comments, and votes are closed.