Skip to content

Commit e10fbf9

Browse files
committed
Add explanation for shifting range in random number generation
1 parent 20ea364 commit e10fbf9

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

‎Sprint-2/1-key-exercises/4-random.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;
1919
// This function multiplies the random decimal by the range size. Since Math.random() represents numbers >=0 and <1, this expression produces value anywhere from 0 up to 100, excluding 100.
2020
// Example to justify expression: 0.876 * 100 = 87.6
2121
//-Math.floor: This static method rounds down to the nearest whole number, discarding the decimal. This turns the continuous range into whole numbers, from 0 - 99.
22-
// That is 87.6 becomes 87.
22+
// That is 87.6 becomes 87.
23+
// + minimum: This shifts the whole range up by adding 1. So instead of landing on 0 - 99, we have 1 - 100.

0 commit comments

Comments
 (0)