appolo-utils
Advanced tools
Comparing version 0.0.15 to 0.0.16
@@ -8,3 +8,3 @@ "use strict"; | ||
} | ||
static random(min, max) { | ||
static random(min, max, floating = false) { | ||
if (max === undefined) { | ||
@@ -14,4 +14,17 @@ max = min; | ||
} | ||
min = Math.ceil(min); | ||
max = Math.floor(max); | ||
let isInt = !floating && Number.isInteger(min) && Number.isInteger(min); | ||
if (isInt) { | ||
return Numbers.randomInt(min, max); | ||
} | ||
min = Math.min(min, max); | ||
max = Math.max(max, max); | ||
return (Math.random() * (max - min + 1)) + min; | ||
} | ||
static randomInt(min, max) { | ||
if (max === undefined) { | ||
max = min; | ||
min = 0; | ||
} | ||
min = Math.ceil(Math.min(min, max)); | ||
max = Math.floor(Math.max(min, max)); | ||
return Math.floor(Math.random() * (max - min + 1)) + min; | ||
@@ -18,0 +31,0 @@ } |
@@ -7,3 +7,3 @@ export class Numbers { | ||
public static random(min: number, max?: number): number { | ||
public static random(min: number, max?: number, floating: boolean = false): number { | ||
@@ -15,4 +15,23 @@ if (max === undefined) { | ||
min = Math.ceil(min); | ||
max = Math.floor(max); | ||
let isInt = !floating && Number.isInteger(min) && Number.isInteger(min); | ||
if (isInt) { | ||
return Numbers.randomInt(min, max); | ||
} | ||
min = Math.min(min, max); | ||
max = Math.max(max, max); | ||
return (Math.random() * (max - min + 1)) + min; | ||
} | ||
public static randomInt(min: number, max?: number): number { | ||
if (max === undefined) { | ||
max = min; | ||
min = 0; | ||
} | ||
min = Math.ceil(Math.min(min, max)); | ||
max = Math.floor(Math.max(min, max)); | ||
return Math.floor(Math.random() * (max - min + 1)) + min; | ||
@@ -19,0 +38,0 @@ } |
@@ -17,3 +17,3 @@ { | ||
"main": "./index.js", | ||
"version": "0.0.15", | ||
"version": "0.0.16", | ||
"license": "MIT", | ||
@@ -20,0 +20,0 @@ "repository": { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
50731
966