阅读 154

Math / 随机数生成

Math / 随机数生成

 /**

     *  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

我是Eric,手机号是13522679763

来源https://www.cnblogs.com/eric-share/p/14729435.html

文章分类
后端
文章标签
版权声明:本站是系统测试站点,无实际运营。本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 XXXXXXo@163.com 举报,一经查实,本站将立刻删除。
相关推荐