Math

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<script type="text/javascript">
document.write(Math.random() * (3-1)+1+'<br>'); // 1<=返回结果 < 3
document.write(Math.random() * (20 - 10 ) + 10) //20 <= 返回结果 <20
//var 变量名 = Math.floor(Math.random()*(Y+1-x)+x) 公式
//Math.random()*(Y+1-x)+x
</script>
</body>
</html>

原文地址:https://www.cnblogs.com/jiaqi818/p/12625754.html