可以使用以下代码生成随机数:
复制
```javascript // 生成0到1之间的随机数 var randomNum = Math.random();
// 生成指定范围内的随机整数 function getRandomInt(min, max) { min = Math.ceil(min); max = Math.floor(max); return Math.floor(Math.random() * (max - min 1)) min; }
console.log(randomNum); console.log(getRandomInt(1, 10)); ```