<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=BIG5">
<title>隨機產生亂數</title>
<Script type ="text/javascript">
var a=0,b=0,c=0;
var minNum = 0;
var maxNum = 7;
function add(){
a = Math.floor( Math.random() * (maxNum - minNum + 1) ) + minNum;
b = Math.floor( Math.random() * (maxNum - minNum + 1) ) + minNum;
c = Math.floor( Math.random() * (maxNum - minNum + 1) ) + minNum;
if(b==a)
{b=b+1;}
if(c==a)
{c=c+2;}
if(c==b)
{c=c+1;}
document.write("亂數",+a,+b,+c);
}
</Script>
</head>
<input type="button" value="submit" onclick="add()"/>
<body>
<h2>亂數不重複</h2>
</body>
</html>
沒有留言:
張貼留言