diff options
| author | ST-DDT <[email protected]> | 2023-01-24 23:00:07 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-01-24 22:00:07 +0000 |
| commit | 2b84b3389a2719e0f365055990a51673acd07ac9 (patch) | |
| tree | 8aa29577a02ae952ad5321690d4f1d12c6e410c4 /src/modules | |
| parent | 3a44d5fa48e8b28a7b9422a18262e39af1d1cb91 (diff) | |
| download | faker-2b84b3389a2719e0f365055990a51673acd07ac9.tar.xz faker-2b84b3389a2719e0f365055990a51673acd07ac9.zip | |
fix(helpers): uniform distribution in helpers.arrayElements (#1770)
Diffstat (limited to 'src/modules')
| -rw-r--r-- | src/modules/helpers/index.ts | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/src/modules/helpers/index.ts b/src/modules/helpers/index.ts index 8d10ced9..8492a096 100644 --- a/src/modules/helpers/index.ts +++ b/src/modules/helpers/index.ts @@ -594,8 +594,9 @@ export class HelpersModule { let temp: T; let index: number; + // Shuffle the last `count` elements of the array while (i-- > min) { - index = Math.floor((i + 1) * this.faker.number.float({ max: 0.99 })); + index = this.faker.number.int(i); temp = arrayCopy[index]; arrayCopy[index] = arrayCopy[i]; arrayCopy[i] = temp; |
