Express Your Love for Coding!
Explore CodeSweetly's Shop for an array of stylish products to enhance your coding experience.
Shop nowWhenever you invoke Math.random(), the method returns a random number between zero (inclusive) and one (exclusive).
In other words, Math.random()
outputs a random number that is equal to or greater than zero (0
) but less than one (1
).
Math.random()
MethodMath.random()
accepts no argument. Here is the syntax:
Below are examples of the Math.random()
method.
0
(inclusive) and 1
(exclusive)Invoke Math.random()
to get a random number between 0
(inclusive) and 1
(exclusive).
0
(inclusive) and 1
(inclusive)Math.random()
to get a random number between 0
(inclusive) and 1
(exclusive).1
to the maximum value (1
).0
(inclusive) and 1
(inclusive).0
(inclusive) and 3
(exclusive)Math.random()
to get a random number between 0
(inclusive) and 1
(exclusive).Math.random()
’s output by 3
to get a random number between 0
(inclusive) and 3
(exclusive).0
(inclusive) and 3
(inclusive)Math.random()
to get a random number between 0
(inclusive) and 1
(exclusive).1
to the maximum value (3
).0
(inclusive) and 3
(inclusive).0
(inclusive) and 3
(exclusive)Math.random()
to get a random number between 0
(inclusive) and 1
(exclusive).Math.random()
’s output by 3
to get a random number between 0
(inclusive) and 3
(exclusive).Math.floor()
method to round down step two’s result to the nearest integer.0
(inclusive) and 3
(inclusive)Math.random()
to get a random number between 0
(inclusive) and 1
(exclusive).1
to the maximum value (3
).0
(inclusive) and 3
(inclusive).Math.floor()
method to round down step three’s result to the nearest integer.5
(inclusive) and 10
(exclusive)Math.random()
to get a random number between 0
(inclusive) and 1
(exclusive).Math.random()
’s output with the difference between the maximum (10
) and the minimum (5
) value to get a random number between 0
(inclusive) and 5
(exclusive).5
) to step two’s result to get a random number between 5
(inclusive) and 10
(exclusive).5
(inclusive) and 10
(inclusive)Math.random()
to get a random number between 0
(inclusive) and 1
(exclusive).5
) from the maximum (10
).1
to step two’s result.0
(inclusive) and 5
(inclusive).5
) to step four’s result to get a random number between 5
(inclusive) and 10
(inclusive).5
(inclusive) and 10
(inclusive)Math.random()
to get a random number between 0
(inclusive) and 1
(exclusive).5
) from the maximum (10
).1
to step two’s result.0
(inclusive) and 5
(inclusive).5
) to step four’s result to get a random number between 5
(inclusive) and 10
(inclusive).Math.floor()
method to round down step five’s result to the nearest integer.