标签:随机 div 随机数 title max n+1 javascrip 整数 pre
转换随机数为指定范围的整数
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>
标签:随机 div 随机数 title max n+1 javascrip 整数 pre
原文地址:http://www.cnblogs.com/xinxinxinxin/p/6673521.html