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 L
andN
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.