Skip to content

Commit 89a16d1

Browse files
committed
Update-Explain random number generation with Math.random and Math.floor
1 parent b5135ac commit 89a16d1

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;
77
//num represents a randomly generated whole number between 1 and 100.
88

99
// Try breaking down the expression and using documentation to explain what it means
10-
// Math.random() generates a random decimal number greater than or equal to 0 and less than 1. Multiplying it by 100 gives a number between 0 and 100.
10+
// Math.random() generates a random decimal number greater than or equal to 0 and less than 1. Multiplying by 100 gives a number between 0 and up to, but not including 100.
1111
// Math.floor() always rounds down and returns the largest integer less than or equal to a given number in this case between 0 and 99. Finally, adding 1 changes the range to 1–100.
1212
// Math.floor(Math.random() * (maximum - minimum + 1))
13-
// Math.floor(Math.random() * (100 - 1 + 1)
13+
// Math.floor(Math.random() * (100 - 1 + 1))
1414
// Math.floor(Math.random() * 100)
1515
// Math.random give any random number between 0 to 1 example 0.225 * 100 = 22.5
1616
// Math.floor rounds that number to a whole number so 22.5 will become 22

0 commit comments

Comments
 (0)