Don't like ads? PRO users don't see any ads ;-)
Guest

random

By: andrew4582 on Feb 20th, 2012  |  syntax: JavaScript  |  size: 0.45 KB  |  hits: 69  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
This paste has a previous version, view the difference. Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1.         function random(min,max){
  2.                 if(max == null || max == undefined){
  3.                         max = min;
  4.                         min = 0;
  5.                 }
  6.                 min = min || 0;
  7.                 max = max || 4000000;
  8.                
  9.                 if(min >= max){
  10.                         min = max + 1;
  11.                 }
  12.                
  13.                 while(true){
  14.                         var val = _random(max);
  15.                         if(min >= val)
  16.                                 continue;
  17.                         return val;
  18.                 }
  19.         }
  20.         function _random(max){
  21.                 if(!max || max <= 0)
  22.                         max = 101;
  23.                
  24.                 var num = Math.floor(Math.random()* max);
  25.                
  26.                 if(num === 0)
  27.                         num = 1;
  28.  
  29.                 return num;
  30.         }