generate random number nodejs
const randomNumber = Math.floor(Math.random() * 100);
console.log(randomNumber);
- The
Math.random()
function generates a random floating-point number between 0 (inclusive) and 1 (exclusive). - We multiply the result of
Math.random()
by 100 to expand the range of the random number. - The
Math.floor()
function is used to round down the resulting number to the nearest integer. - Finally, we log the random number to the console using
console.log()
.