We can easily do this by using a combination of built-in
Let’s start by using
Math.random() to generate a random number. Now we will take that and multiply it by
max - min + 1.
Because of how the
Math.random() function works, we will need to then add the minimum value to this.
Once we are done, we pass it through a
Math.floor() to get an absolute integer value (not a float).
We can wrap this all into a function as follows: