Skip to content

Commit ae3b1cd

Browse files
committed
amended answer to 4-random.js to be more detailed
1 parent d7abaa6 commit ae3b1cd

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,7 @@ const maximum = 100;
33

44
const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;
55

6-
// num generates a random number between 1 and 100
6+
// minimum and maximum store the lowest and highest numbers that can be generated.
7+
// Math.random() generates a random decimal between 0 and 1. This value is multiplied by (maximum - minimum + 1) to produce a random number within the required range.
8+
// Math.floor() rounds the result down to the nearest whole number producing a number from 0 to 99.
9+
// Minimum is then added, shifting the range to 1–100. This ensures that every whole number between 1 and 100 has an equal chance of being generated.

0 commit comments

Comments
 (0)