2016年6月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>