如何在JavaScript中生成两个数字之间的随机数?
若要生成两个数字之间的随机数,请使用Math.random()方法。
示例
您可以尝试运行以下代码以获取介于最小值和最大值之间的随机数-
<!DOCTYPE html>
<html>
<body>
<script>
function randomInt(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min)) + min;
}
alert(randomInt(5,25));
</script>
</body>
</html>热门推荐
10 前程祝福语简短暖心
11 明天早上祝福语简短的话
12 猪年给老师祝福语简短
13 欢天喜地盖新房祝福语简短
14 收围巾的祝福语简短
15 毕业祝福语简短给同学
16 简短古文生日祝福语
17 祝父母节日祝福语简短
18 感恩父亲贺卡祝福语简短