Skip to content

Commit c66d6a4

Browse files
authored
Enhance comments for random number generation logic
Added detailed comments explaining the random number generation process.
1 parent 3629cf5 commit c66d6a4

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,8 @@ console.log (num);
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+
// Math.random() : Generates a pseudorandom decimal number. [0, 1)
12+
// Math.random() * (maximum - minimum + 1) : Scales the random value so its width equals the number of integers from `minimum` to `maximum`. [0, maximum - minimum + 1)
13+
// Math.floor(Math.random() * (maximum - minimum + 1)) : Floors the scaled value, producing a random integer starting at 0. Integers in [0, maximum - minimum + 1), i.e. {0, 1, ..., maximum - minimum}
14+
// Math.floor(Math.random() * (maximum - minimum + 1)) + minimum` : Shifts the previous result upward by `minimum`, producing a random integer between `minimum` and `maximum`, inclusive. Integers in [minimum, maximum + 1), i.e. {minimum, minimum + 1, ..., maximum}

0 commit comments

Comments
 (0)