Skip to content

Commit 86a4ec4

Browse files
authored
Update comments for clarity on random number generation
1 parent f0bf490 commit 86a4ec4

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,16 @@ console.log(num);
99
// It will help to think about the order in which expressions are evaluated
1010
// Try logging the value of num and running the program several times to build an idea of what the program is doing
1111

12-
// Math.random() returns a random decimal number between 0 and 1
13-
// (maximum - minimum + 1) represents the size of range of numbers we want to include. We add +1 because both minim and maximum are included in the range
14-
// Math.random() * (maximum - minimum + 1) gives us a random decimal between 0 and 100, but still decimal
15-
// Math.floor() rounds down to the nearest whole number. So this. turns decimals like 99.9 into 99
16-
// + minimum since minimum = 1, this shifts the entire random range up by 1. so instead of 0-100, the range becomes 1-100
17-
// num should return a random integer between 1 and 100
12+
// Math.random() returns a random decimal in the interval [0, 1)
13+
14+
// (maximum - minimum + 1) gives the size of the interval [minimum, maximum]
15+
16+
// Math.random() * (maximum - minimum + 1)
17+
// gives a random decimal in the interval [0, 100)
18+
19+
// Math.floor() rounds down to the nearest whole number
20+
21+
// + minimum shifts the interval upward by 1,
22+
// so the final integer range becomes [1, 100]
23+
24+
// num should return a random integer between 1 and 100 inclusive

0 commit comments

Comments
 (0)