zoukankan      html  css  js  c++  java
  • 封装常用方法

    JS封装好的方法现成拿去用

    1.(n,m)之间随机数

      /*
    功能:生成n-m之间的随机整数
    parameter:(n,m)(m,n)()
    return: 随机整数
    by fengchao2018-4-3
      * */
      function getRandom(n,m){
    //    1.转换数据类型
        n=Number(n);
        m=Number(m);
    //    2.判断是否是有效数字
        if (isNaN(n)||isNaN(m)){
          return Math.random();
        }
    //    3.n<m,交换位置
        if (n<m){
          var temp=n;
          n=m;
          m=temp;
        }
        return Math.round(Math.random()*(n-m)+m);
      }
      console.log(getRandom(10,1));
  • 相关阅读:
    iOS
    iOS
    iOS
    iOS
    iOS
    iOS
    iOS
    iOS
    iOS
    iOS
  • 原文地址:https://www.cnblogs.com/liangfc/p/8710869.html
Copyright © 2011-2022 走看看