Math
is a built-in object in JavaScript that contains different methods and properties used to perform mathematical operations. It contains a random()
function, which is used to return a random number in the range from 0 to 1.
Math.random();
Number
: The function returns a random number in range 0 (inclusive) to 1 (exclusive). It is of the Number
type.// returns a random number from 0 to 1console.log("random() = " + Math.random());// returns a random number from 1 to 10console.log("random()*10 = " + Math.random()*10);// returns a random number starting from 5console.log("random()+5 = " + (Math.random()+5));// returns a random number starting from 5 to 15console.log("random()*10+5 = " + (Math.random()*10+5));