js生成10个20-50之间的随机数(包含20和50)

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <title>生成10个20-50之间的随机数</title>
  <style type="text/css">
  </style>
</head>

<body>
  <script type="text/javascript">
  function getRandomIntInclusive(min, max) {
    min = Math.ceil(min);
    max = Math.floor(max);
    return Math.floor(Math.random() * (max - min + 1)) + min; //含最大值,含最小值 
  }  
  var arr = [];
  for (var i = 0; i < 10; i++) {
    var num = getRandomIntInclusive(20, 50);
    num = parseInt(num, 10);
    arr.push(num);
  }
  console.log(arr); //生成10个20-50之间的随机数
  </script>
</body>

</html>

posted @ 2019-04-08 17:49  徐同保  阅读(5212)  评论(0编辑  收藏  举报