diff options
Diffstat (limited to 'src/random.ts')
| -rw-r--r-- | src/random.ts | 8 |
1 files changed, 6 insertions, 2 deletions
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<T = string>( array: ReadonlyArray<T> = ['a', 'b', 'c'] as unknown as ReadonlyArray<T> ): 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]; } /** |
