In JavaScript, you can generate a random number with the Math.random() function.
Math.random() returns a random floating-point number ranging from 0 to less than 1 (inclusive of 0 and exclusive of 1)
Example 1: Generate a Random Number
// generating a random number
const a = Math.random();
console.log(a);
Output
0.5856407221615856
Here, we have declared a variable a and assigned it a random number greater than or equal to 0 and less than 1.