SHOW:
|
|
- or go back to the newest paste.
| 1 | - | function random(max){
|
| 1 | + | function random(min,max){
|
| 2 | - | if(!max || max <= 0) |
| 2 | + | if(max == null || max == undefined){
|
| 3 | - | max = 101; |
| 3 | + | max = min; |
| 4 | - | |
| 4 | + | min = 0; |
| 5 | - | var num = Math.floor(Math.random()* max); |
| 5 | + | } |
| 6 | - | |
| 6 | + | min = min || 0; |
| 7 | - | if(num === 0) |
| 7 | + | max = max || 4000000; |
| 8 | - | num = 1; |
| 8 | + | |
| 9 | if(min >= max){
| |
| 10 | - | return num; |
| 10 | + | min = max + 1; |
| 11 | - | } |
| 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 | } |