If you don't like reading skip to the end
So i have 3 random number
local random1 = math.random(1,10)
local random2 = math.random(1,10)
local random3 = math.random() -- or math.random(0,1)
Now let's say if the value of the random3 is 0 then the value of random1 and random2 can be anywhere between 1 and 10, but if the value of random3 is 1 then the value of random2 must be lower than random1. But the value of random 1, 2 must always be between 1 and 10.
local random3 = math.random()
if random3 == 0 then
local random1 = math.random(1,10)
local random2 = math.random(1,10)
else -- or else if random3 == 1 then
local random1 = math.random(2,10)
local random2 =
end
Now the question is in line 7, how do i make the value lower than the value i get on random1, for example if i get the value of 5 on random1 then the value of random2 must be lower than 5 which means it must be between 1 and 4, i also made the random1 get a value between 2,10 because if it gets 1 then that won't work because there isn't anything lower than 1 that is higher than 1.
I mean i could do this
local random3 = math.random()
if random3 == 0 then
local random1 = math.random(1,10)
local random2 = math.random(1,10)
else -- or else if random3 == 1 then
local random1 = math.random(2,10)
repeat
local random2 = math.random(1,9)
until random2 < random1
end
it would work but if there is an alternative way other than using repeat or a long list of "if else" then i would take it. And also i need to change 2 textlabel from the 2 random values so, the current script would be like this.
local number1 = workspace.Number1.SurfaceGui.TextLabel
local number2 = workspace.Number2.SurfaceGui.TextLabel
local function variable ()
local random3 = math.random()
if random3 == 0 then
local random1 = math.random(1,10)
local random2 = math.random(1,10)
number1.Text = tostring(random1)
number2.Text = tostring(random2)
else -- or else if random3 == 1 then
local random1 = math.random(2,10)
number1.Text = tostring(random1)
repeat
local random2 = math.random(1,9)
number2.Text = tostring(random2)
until random2 < random1
end
end
anyeventlistener:Connect(variable)
So overall the problem is.. How do i make a random value lower than another random value

8 comments
Probably the longest question i made so far in scripting helpers
Do you need it to be a whole number, or can there be decimals?
^ not part of the question and totally irrelevant.
Not likely, but that repeat until of yours could, in theory, go on forever.
Not irrelevant.
Commented an answer after realizing I left my browser with this page open for 20 mins. Nvm.
math.random() -- or math.random(0,1)It returns a number between 0 and 1, not just 0 and 1. https://www.robloxdev.com/articles/Lua-Libraries/math#random^ i only said what i found