首页 > 其他 > 详细

Math / 随机数生成

时间:2021-05-04 17:21:03      阅读:14      评论:0      收藏:0      [点我收藏+]
  /**
     *  Math 
     * 
     *  Math.PI 表示 圆周率
    */
  //  console.log(Math);

  // console.log(Math.PI);

  // Math.ceil() 向上取整
  // console.log(Math.ceil(1.1));//2

  // Math.floor() 向下取整
  // console.log(Math.floor(1.9));// 1


  // Math.round() 四舍五入
    // console.log(Math.round(1.9));// 2
    // console.log(Math.round(1.5));// 2
    // console.log(Math.round(1.4));// 1

    /**
     * Math.random()
     *  可以生成一个 0-1 之间的随机数
     *  生成一个 0-10 之间的随机数
     *  Math.round(Math.random() * 10)
     * 生成一个 0-x 之间的随机数
     *  Math.round(Math.random() * x)
     *  
     *  生成一个 1-10 之间的随机数
     *  Math.round(Math.random() * 9) + 1
     * 
     *   生成一个 x-y 之间的随机数
     *   Math.round(Math.random() * (y-x)) + x
    */  

  //  console.log(Math.random()); 
  //  生成一个 1-6 之间的随机数 
  // console.log(Math.round(Math.random() * 5 + 1));  


  // // max()  获取多个 数中的最大值 
  // var max = Math.max(10,45,30)
  // console.log(max);

  //  // min()  获取多个 数中的最小值 
  // var min = Math.min(10,45,30)
  // console.log(min);


   // Math.pow(x,y)  返回 X 的 y 次幂 
   console.log(Math.pow(2,3));  // 2 * 2 * 2


    // Math.sqrt(9)  开方
    console.log(Math.sqrt(9));  // 3

Math / 随机数生成

原文:https://www.cnblogs.com/eric-share/p/14729435.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!