Math对象
Math是js系统提供的一个对象
// 里面有属性和方法用来做数学类操作
// 获取圆周率
// console.log(Math.PI)
// 获取随机数
// console.log( Math.random() ); // 随机数是0~1之间的小数,有可能是0,但不可能是1
// // 0~10之间的整数
// console.log( parseInt(Math.random()*10 )); // 0~10的整数,可能是0,不能是10
// // 10~20之间的整数
// console.log( parseInt(Math.random()*10)+10 );
// // 0~5之间的整数
// console.log( parseInt(Math.random()*5) );
// 20~100之间的整数
// 0~80之间的整数+20
// console.log( parseInt(Math.random()*80) + 20);
这是获取范围类随机整数的函数
function getRandom(a,b){
// // var a = 5;
// // var b = 10;
// // a~b之间的随机整数
// // console.log(parseInt(Math.random()*(b-a)) + a)
// var max = a;
// var min = b;
// if(a<b){
// max = b;
// min = a;
// }
// return parseInt(Math.random()*(max-min)) + min
// }
// var res = getRandom(6,9)
// console.log(res);
// var res = getRandom(9,6)
// // -(随机数*3) 包含0,不包含-3
// console.log(res);
这是这个函数的引用方法,得提前封装!!!
</script>
<!-- <script src="./tools.js"></script> -->
<script>
// var num = getRandom(5,'10')
// console.log(num);
</script>

浙公网安备 33010602011771号