How do I ensure the number is between 0 and 50?

This section talks about using Math.floor(Math.random()*50); to get a number between 0 and 50.
But Math.random generates a number in the range 0–1 (inclusive of 0, but not 1) and
Math.floor rounds DOWN to the nearest whole number. So… to get a number that is between 0 and 50, wouldn’t we actually need to multiply by 51?

2 Likes

Hi, I am not an expert in mathematics or programming but from what I read in this link (), this example is shown:
console.log (Math.floor (5));
// expected output: 5
And if the literal expression of this function is taken, it would not be necessary to multiply it by 51; the expression is the following: “returns the largest integer less than or ** equal ** to a given number.”, paying special attention to the word “equal”.