Skip to content

Commit 9d6eec5

Browse files
Shinigami92ST-DDT
andcommitted
feat: use random.numeric
Co-authored-by: ST-DDT <[email protected]>
1 parent 59bbc70 commit 9d6eec5

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

src/datatype.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -324,19 +324,15 @@ export class Datatype {
324324
throw new FakerError(`Max ${max} should be larger then min ${min}.`);
325325
}
326326

327-
// TODO @Shinigami92 2022-04-07: Use faker.random.numeric() from https://github.com/faker-js/faker/pull/797
328-
const generateRandomBigInt = (length: number) =>
329-
BigInt(
330-
Array.from(
331-
{ length },
332-
() => '0123456789'.split('')[this.number({ min: 0, max: 9 })]
333-
).join('')
334-
);
335-
336327
const delta = max - min;
337328

338329
const offset =
339-
generateRandomBigInt(delta.toString(10).length) % (delta + BigInt(1));
330+
BigInt(
331+
this.faker.random.numeric(delta.toString(10).length, {
332+
allowLeadingZeros: true,
333+
})
334+
) %
335+
(delta + BigInt(1));
340336

341337
return min + offset;
342338
}

0 commit comments

Comments
 (0)