2016年6月2日 星期四

期末考

3個數字可重複
<html>
<script>
var a,b,c,maxNum,minNum;
maxNum=9;
minNum=0;
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;
document.write(a,b,c);
</script>
<body>
</body>
</html>
不重複
<html>
<script>
var a,b,c,maxNum,minNum;
maxNum=9;
minNum=0;

            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;

            while(a==b){
b= Math.floor( Math.random() * (maxNum - minNum + 1) ) + minNum;
}            
           while(a==c || b==c){
c= Math.floor( Math.random() * (maxNum - minNum + 1) ) + minNum;
}
document.write(a,b,c);
</script>
<body>
</body>
</html>