79643309

Date: 2025-05-29 04:55:11
Score: 0.5
Natty:
Report link
Math.floor(Math.random() * (80-50+1)) + 50

How,

Considering, 50 as the min and 80 as max of the range.

  1. The Math.random() results in a floating point number between 0 and 1 (0 inclusive, 1 exclusive).

  2. Multiply it by 31 (the difference of the range + 1) results in a number between 0 and 31 (not including 31).

  3. Adding the minimum value (in here 50) shifts it to a number between min and 81 (exclusive). So, the number is between min and min + 31.

  4. Math.floor() ensures we round down, so that all integer values from min to max are possible. (if we used Math.ceil(), it skips minimum value, e.g. 50.6)

In step 2, the +1 ensures that the max (in this example 80) is included after flooring. Without it, the max would be excluded (highest possible result from Math.floor() would be max - 1).

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Starts with a question (0.5): How
  • Low reputation (1):
Posted by: Charith J De Silva