Nodejs Random Number Get random(_minNum,_maxNum,_rejArr)

Here you can find the source of random(_minNum,_maxNum,_rejArr)

Method Source Code

/**/*from  ww  w  . ja v  a  2 s .com*/
  * @description generate a random number
  * @author x.radish
  * @param {int} _minNum The min number
  * @param {int} _maxNum The max number
  * @param {Array} _rejArr reject array
  * @return {int} -1 error
  */
 function random(_minNum,_maxNum,_rejArr){
     var minNum=_minNum||4,
         maxNum=_maxNum||17,
         rejArr=_rejArr||[],
         num=-1,
         flag=true;
     num = Math.floor(Math.random()*(maxNum-minNum+1)+minNum);
     if(rejArr.length>maxNum-minNum) return -1;
     for(var i=0,len=rejArr.length;i<len;i++){
         if(num==rejArr[i]){
             flag=false; break;
         }
     }
     if(flag) return num; else return random(minNum,maxNum,rejArr);
 }

Related

  1. iRandom(a, b)
    Math.iRandom = function(a, b){
      if (arguments.length == 1){
        return Math.round(Math.random() * a);
      }else if (arguments.length == 2){
        return a + Math.round(Math.random() * (b - a));
    };
    
  2. rand(l, u)
    Math.rand = function (l, u) {
      return Math.floor((Math.random() * (u - l + 1)) + l);
    };
    
  3. rand(min, max)
    Math.rand = function(min, max) { 
      return Math.floor(Math.random() * (max - min) + min); 
    
  4. range(a, b)
    Math.range = function (a, b) {
      return this.floor(this.random() * a) + b;
    };
    
  5. random(low, high)
    function random(low, high) {
      var rand = (Math.random() * high) + low;
      return rand;
    
  6. random(min, max)
    function random(min, max) {
        return Math.floor(Math.random() * (max - min)) + min;
    
  7. random(min, max)
    function random(min, max) {
       return Math.floor(Math.random() * (max - min + 1)) + min;
    
  8. random(min, max)
    function random(min, max) {
      return Math.floor(Math.random() * max) + min;