1 <!-- math.random 获取0-1的随机数 2 math.floor 向下取整 3 math.ceil 向上取整 --> 4 <!DOCTYPE html> 5 <html lang="en"> 6 <head> 7 <meta charset="UTF-8"> 8 <title>Document</title> 9 <script type="text/javascript"> 10 var iPi = Math.PI; 11 alert(iPi); 12 var iNum = Math.random(); 13 alert(iNum); 14 alert(Math.floor(5.6)); //弹出5 15 alert(Math.ceil(5.6)); //弹出6 16 17 console.log(iNum); // 调试代码的一种方式,浏览器检查元素,选择console菜单 18 19 // 生成10-20的随机整数 20 var iN01 = 10; 21 var iN02 = 20; 22 var arr2 = [] 23 for(var i=0;i<40;i++) 24 { 25 var iNum02 = Math.floor((iN02 - iN01 +1)*Math.random()) + iN01; 26 arr2.push(iNum02); 27 } 28 console.log(arr2); 29 </script> 30 </head> 31 <body> 32 33 </body> 34 </html>