aboutsummaryrefslogtreecommitdiff
path: root/src/modules/number
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules/number')
-rw-r--r--src/modules/number/index.ts15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/modules/number/index.ts b/src/modules/number/index.ts
index 292fbcf2..cef0b27c 100644
--- a/src/modules/number/index.ts
+++ b/src/modules/number/index.ts
@@ -43,12 +43,19 @@ export class NumberModule {
}
const { min = 0, max = min + 99999 } = options;
+ const effectiveMin = Math.ceil(min);
+ const effectiveMax = Math.floor(max);
- if (max === min) {
- return min;
+ if (effectiveMin === effectiveMax) {
+ return effectiveMin;
}
- if (max < min) {
+ if (effectiveMax < effectiveMin) {
+ if (max >= min) {
+ throw new FakerError(
+ `No integer value between ${min} and ${max} found.`
+ );
+ }
throw new FakerError(`Max ${max} should be greater than min ${min}.`);
}
@@ -56,7 +63,7 @@ export class NumberModule {
// @ts-expect-error: access private member field
this.faker._mersenne;
- return mersenne.next({ min, max: max + 1 });
+ return mersenne.next({ min: effectiveMin, max: effectiveMax + 1 });
}
/**