Skip to content

Commit 02c8df6

Browse files
committed
Enhance random number generation explanation and documentation
1 parent 3fca4c9 commit 02c8df6

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,14 @@ const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;
77
// Try breaking down the expression and using documentation to explain what it means
88
// It will help to think about the order in which expressions are evaluated
99
// Try logging the value of num and running the program several times to build an idea of what the program is doing
10+
11+
console.log(num);
12+
13+
// I understand that Math.random() generates a random number between 0 and 1,
14+
// and multiplies it by the range (maximum - minimum + 1) to get a number in that range.
15+
// and then adds the minimum to shift the range to start from the minimum value 1 -> 100 rather than 0 -> 99.
16+
// finally, Math.floor() rounds the number down.
17+
18+
// docs for Math.random() and Math.floor() I used:
19+
// https://www.google.com/search?q=Math.random+mdn
20+
// https://www.google.com/search?q=Math.floor+mdn

0 commit comments

Comments
 (0)