(min, max)
| 40 | |
| 41 | // Return a random integer from the interval [min,max], inclusive. |
| 42 | export const random = function(min, max) { |
| 43 | |
| 44 | if (max === undefined) { |
| 45 | // use first argument as max, min is 0 |
| 46 | max = (min === undefined) ? 1 : min; |
| 47 | min = 0; |
| 48 | |
| 49 | } else if (max < min) { |
| 50 | // switch max and min |
| 51 | const temp = min; |
| 52 | min = max; |
| 53 | max = temp; |
| 54 | } |
| 55 | |
| 56 | return floor((Math.random() * (max - min + 1)) + min); |
| 57 | }; |
| 58 |