首页 > 其他 > 详细

4月6日--求指定范围的随机数

时间:2017-04-06 15:43:53      阅读:191      评论:0      收藏:0      [点我收藏+]

  转换随机数为指定范围的整数
  1、Math.floor(Math.random()*(MAX-MIN+1))+MIN

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Math的常用方法3</title>
    <script type="text/javascript">
        var n=Math.random();//0-1
        console.log(n);
        //转换随机数为指定范围的整数
        //Math.floor(Math.random()*(MAX-MIN+1))+MIN
        //[0,100] 
        // n=Math.floor(Math.random()*101);
        //[4,57]
        n=Math.floor(Math.random()*54)+4;
        console.log(n);
    </script>
</head>
<body>
    
</body>
</html>

 

4月6日--求指定范围的随机数

原文:http://www.cnblogs.com/xinxinxinxin/p/6673521.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!