zoukankan      html  css  js  c++  java
  • [JS]两个常用的取随机整数的函数

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
     <head>
      <title> New Document </title>
      <meta name="Generator" content="EditPlus">
      <meta name="Author" content="">
      <meta name="Keywords" content="">
      <meta name="Description" content="">
     </head>
    
     <body onload="test();">
      
     </body>
    </html>
    <script type="text/javascript">
    <!--
        
        function test(){
            for(var i=0;i<10;i++){
                console.log(getRndFromZeroToN(4));
            }
    console.log("---------------------------");
            for(var i=0;i<10;i++){
                console.log(getRndBetween(1,4));
            }
        }
    
    //------------------------------------------------------------
    // 得到0到N(包括0和N)的随机整数
    // 如果要得到数组里面的一个要把数组长度减一
    //------------------------------------------------------------
    function getRndFromZeroToN(n){
        return Math.floor(Math.random()*(n+1));
    }
    //------------------------------------------------------------
    // 得到lowerLimit到upperlimit(包括端点值)的随机整数
    //------------------------------------------------------------
    function getRndBetween(lowerLimit,upperLimit){
        return Math.floor(Math.random()*(upperLimit-lowerLimit+1))+lowerLimit;
    }
    //-->
    </script>

    2019年3月10日16点03分

  • 相关阅读:
    C#事件理解
    二叉排序树查找算法代码
    二叉排序树查找算法代码
    深度学习——02、深度学习入门——卷积神经网络
    深度学习——02、深度学习入门——卷积神经网络
    程序员表白代码
    程序员表白代码
    程序员表白代码
    vbs实现消息轰炸
    vbs实现消息轰炸
  • 原文地址:https://www.cnblogs.com/heyang78/p/10504650.html
Copyright © 2011-2022 走看看