URGENT: Hello I need a way to get random math operator

Hi guys I need a way to get a random math operation like *, -, /, and +. Any help will be greatly appreciated!

1 Like

Try this out:

local operations = {"/", "*", "-", "+"}
local rand = operations[math.random(1, #operations)]

warn(rand) -- returns a random math operator (/, *, etc.)

Try this:

local function randMath(a, b)
	local op = math.random(1, 4)
	if op == 1 then
		return a + b
	elseif op == 2 then
		return a - b
	elseif op == 3 then
		return a * b
	else
		return a / b
	end
end
2 Likes

Thanks, Guys, I’ll test them out

If you want to get a standalone random math operator, use my solution. Otherwise if you want to do an equation between two numbers and a random math operator, use @Maelstorm_1973’s solution.

Ok so basically what I was asking was whether I could use a variable value to multiply two numbers together like 2 [variable] 3?

1 Like

In that case, you can use @Maelstorm_1973’s solution.