aboutsummaryrefslogtreecommitdiff
path: root/src/modules
diff options
context:
space:
mode:
authorST-DDT <[email protected]>2023-01-24 23:00:07 +0100
committerGitHub <[email protected]>2023-01-24 22:00:07 +0000
commit2b84b3389a2719e0f365055990a51673acd07ac9 (patch)
tree8aa29577a02ae952ad5321690d4f1d12c6e410c4 /src/modules
parent3a44d5fa48e8b28a7b9422a18262e39af1d1cb91 (diff)
downloadfaker-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.ts3
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;