Skip to content

Commit 1fca7d0

Browse files
Improve comments for random number generation logic
Updated comments to clarify the range of random numbers generated.
1 parent af47636 commit 1fca7d0

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@ console.log(num);
1616
// The order of operations is as follows:
1717

1818
// 1. The expression inside the parentheses is evaluated first: (maximum - minimum + 1) which gives us 100 - 1 + 1 = 100
19-
// 2. Then Math.random() is called, which generates a random decimal number between 0 and 1.
20-
// 3. The result of Math.random() is multiplied by the result of step 1, giving us a random decimal number between 0 and 100.
21-
// 4. Math.floor() is then called on the result of step 3, which rounds it down to the nearest whole number, giving us a random integer between 0 and 99.
22-
// 5. Finally, the minimum value (1) is added to the result of step 4, giving us a random integer between 1 and 100.
19+
// 2. Then Math.random() is called, which generates a random decimal number the range [0, 1).
20+
// 3. The result of Math.random() is multiplied by the result of step 1, giving us a random decimal number in the range [0, 100).
21+
// 4. Math.floor() is then called on the result of step 3, which rounds it down to the nearest integer,
22+
// resulting in a value from the set {0, 1, ..., 99\}
23+
// 5. Finally, the minimum value (1) is added to the result of step 4, giving us a random integer in the range [1, 100].
2324

2425
// When num = 99
2526
// math.random gives us 0.98 (or something close to it)

0 commit comments

Comments
 (0)