From 03041201c21ad599bbe1874c375f4f41b94961ba Mon Sep 17 00:00:00 2001 From: Piotr Kuczynski Date: Thu, 31 Mar 2022 19:48:24 +0200 Subject: fix: datatype.number when min = max + precision, throw when max > min (#664) --- src/random.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/random.ts') diff --git a/src/random.ts b/src/random.ts index 0a3b3c5e..f41a67fa 100644 --- a/src/random.ts +++ b/src/random.ts @@ -107,8 +107,12 @@ export class Random { arrayElement( array: ReadonlyArray = ['a', 'b', 'c'] as unknown as ReadonlyArray ): T { - const r = this.faker.datatype.number({ max: array.length - 1 }); - return array[r]; + const index = + array.length > 1 + ? this.faker.datatype.number({ max: array.length - 1 }) + : 0; + + return array[index]; } /** -- cgit v1.2.3