Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
}
function generateRandomInteger (max = Number.MAX_SAFE_INTEGER, min = 0) {
+ if (max < 0) {
+ throw new RangeError('Invalid interval')
+ }
max = Math.floor(max)
- if (min != null || min !== 0) {
+ if (min != null && min !== 0) {
+ if (max < min || min < 0) {
+ throw new RangeError('Invalid interval')
+ }
min = Math.ceil(min)
return Math.floor(Math.random() * (max - min + 1)) + min
}
}
static generateRandomInteger (max = Number.MAX_SAFE_INTEGER, min = 0) {
+ if (max < 0) {
+ throw new RangeError('Invalid interval')
+ }
max = Math.floor(max)
- if (min != null || min !== 0) {
+ if (min != null && min !== 0) {
+ if (max < min || min < 0) {
+ throw new RangeError('Invalid interval')
+ }
min = Math.ceil(min)
return Math.floor(Math.random() * (max - min + 1)) + min
}