Let’s look at this in a few steps while assuming that ourMax is 20 and ourMin is 10.

**Step 1: Math.random**

Math.random() will return a number between 0 and 1 (but not 1)

What’s worth noting here is that while we can get a “0”, we can’t get a “1”, the highest we can get is a 0.99999999999… and so on.

**Step 2: Math.random * ourMax**

Multiplying the output by ourMax will technically increase our range from 0-1 to 0-20 (but not 20)

**Step 3: Math.random * (ourMax - ourMin)**

Let’s remember that ourMax is 20 and ourMin is 10.

Very similar to step 2, it decreases the range back to 0-10 (but not 10), we’ll fix it in a moment.

**Step 4: Math.random * (ourMax - ourMin + 1)**

Because we’re rounding down using math.floor and because we can’t get the highest number in range as an integer, that means no matter the output, it’ll always be rounded down to ourMax - 1. Because even if we got 9.9999… (while our range is 0-10) it’d get rounded down to 9.

Adding 1 fixes that problem, now the highest value we can receive is 10.999999… and it gets rounded down to 10, which is the desired ourMax.

At this point our range is 0-10, because we’re not modifying the minimum output we can receive despite adding a 1, we’re only modifying the maximum possible number.

**Step 5: Math.random * (ourMax - ourMin +1) + ourMin**

This is the last step and it makes our random number generator work in an actual range between 2 numbers. Our lowest possible number is now 10 and highest is 20.

Why? Because we’re adding ourMin **outside** of the Math.floor function:

**Math.floor(Math.random() * (ourMax - ourMin + 1))** + ourMin;

The bolded part is what gets rounded down. After we receive that, we’re separately adding ourMin, which means that even if we got a 0, our final value can’t be lower than ourMin, which in our case is 10, same goes for our maximum value which now can’t be lower than 20.

Hope it made things clearer! Cheers