Math.PI 获取圆周率
console.log( Math.PI );//3.141592653589793
Math.random() 随机数
console.log( Math.random() ); // 随机 0~1之间的小数 - 有可能是0,不可能是1
通常会用到随机整数 - 将随机数扩大10倍 - 取整 - 0~10之间的随机整数
console.log( Math.random() * 10 );
console.log( parseInt( Math.random() * 10 ) );
20~100之间的随机整数
parseInt( Math.random() * 10 ) + 20 // 获取到20~30之间的整数
parseInt( Math.random() * 10 ) + 30 // 获取到30~40之间的整数
parseInt( Math.random() * 80 ) // 获取到的是0~80之间的随机整数
parseInt( Math.random() * 80 ) + 20 // 获取到的是20~100之间的随机整数
15~34之间的随机整数
parseInt( Math.random() * 19 ) + 15
由此可知 a~b之间的随机数就是
Math.random() * (b-a) + a