赞
踩
- <script>
- // 随机数 Math.random() 随机的范围 [0 ,1)左闭右开 包括0但是没有1
- console.log(Math.random()); //0 -0.999999999...
- // 生成0-10的随机数 生成一个0-10的随机数一般我们要加+1,向下取整
- console.log(Math.floor(Math.random() * 11)); //0-10.99999999999
-
- // 生成0-100的随机数
- // Math.floor(Math.random() * 101) //0-100.99999
-
-
- // 生成5-10的随机数
- // 1.生成一个0-5的随机数 ,生成完毕+5
- // console.log(Math.floor(Math.random() * 6) + 5);
-
-
- // 生成一个随机范围的数
- function getRandom(min, max) {
- // 向上取整
- min = Math.floor(min);
- // 向下去整
- max = Math.floor(max);
- // 返回一个随机数
- return Math.floor(Math.random() * (max - min + 1)) + min; //含最大值,含最小值
- }
-
- console.log(getRandom(1, 3));
- </script>
![](https://csdnimg.cn/release/blogv2/dist/pc/img/newCodeMoreWhite.png)
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。