# How do I find a number between 2 numbers

hi, I have a problem with thing to my game

I don’t know how to find number between 2 different numbers, I tried to use this:

``````if number >= 100 and number <= 200 then
--something
end
``````

but it doesn’t seem to work.

If you want the number in between 2, literally, then linear interpolation is your friend.

``````local function lerp(start, goal, alpha)
return start + (goal - start)*alpha
end

print(lerp(100, 200, 0.5)) -- 150
``````

Otherwise not sure what you want.

3 Likes

well, I’m checking for rotation of 2d gui, and if it’s between these 2 numbers then player can continue repairing a power box, if not, then player needs to start again

it’s something like in Flee the Facility when you’re hacking computer

You could use a number range such as

``````local NumberRange = NumberRange.new(1, 5)
local Number = 3

if Number >= NumberRange.Min and Number <= NumberRange.Max then
print("number is between two numbers")
end
``````

This should work!

3 Likes

Why do you need NumberRange for this may I ask? In this instance, it’s basically this:

``````number >= 1 and number <= 5
``````

To OP: Could you explain how it doesn’t work? What’s the value of the `number`?

NumberRange isn’t necessary for this situation, it’s just another method for checking if a number is between two numbers.

You can use math.random. Let me know if you don’t know what it is.

can you show us your whole script?

the issue might be something else

the issue was something different, but it’s already solved.

This should be set as the answer