求任意2个范围之内的随机整数

<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>求任意2个范围之内的随机整数</title>
</head>
<body>
<script type="text/javascript">
function select(start,end){
var total=end-start+1;
return Math.floor(Math.random()*total+start);
}

for(var i=0;i<10;i++){
document.write(select(1,10));
document.write('<br/>');
}
</script>
</body>
</html>

posted @ 2017-04-22 17:27  天--安静  阅读(177)  评论(0编辑  收藏  举报