自己实现随机 a, b 之间的整型
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<script type="text/javascript">
function randint(a, b) {
if(a > b){
a = a + b;
b = a - b;
a = a - b;
}
while(true){
var num = Math.random()*b*10
num = Math.round(num)
if(num >= a && num <= b){
document.write("<p>")
document.write(num)
document.write("</p>")
break;
}
}
}
randint(2,20)
</script>
</body>
</html>
网友评论