From a3514001c0c5849eb8a41b562eda18199886faa1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=9C=A8=20Audrey=20=E2=9C=A8?= Date: Wed, 26 Jun 2024 15:41:02 -0400 Subject: [PATCH] shuffle copied array (#9847) --- libs/common/src/tools/generator/random.ts | 4 ++-- .../generator/core/src/engine/crypto-service-randomizer.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libs/common/src/tools/generator/random.ts b/libs/common/src/tools/generator/random.ts index 6b72e3cd91..1400ed1175 100644 --- a/libs/common/src/tools/generator/random.ts +++ b/libs/common/src/tools/generator/random.ts @@ -31,9 +31,9 @@ export class CryptoServiceRandomizer implements Randomizer { async shuffle(items: Array, options?: { copy?: boolean }) { const shuffled = options?.copy ?? true ? [...items] : items; - for (let i = items.length - 1; i > 0; i--) { + for (let i = shuffled.length - 1; i > 0; i--) { const j = await this.uniform(0, i); - [items[i], items[j]] = [items[j], items[i]]; + [shuffled[i], shuffled[j]] = [shuffled[j], shuffled[i]]; } return shuffled; diff --git a/libs/tools/generator/core/src/engine/crypto-service-randomizer.ts b/libs/tools/generator/core/src/engine/crypto-service-randomizer.ts index a15440836d..5320fad681 100644 --- a/libs/tools/generator/core/src/engine/crypto-service-randomizer.ts +++ b/libs/tools/generator/core/src/engine/crypto-service-randomizer.ts @@ -31,9 +31,9 @@ export class CryptoServiceRandomizer implements Randomizer { async shuffle(items: Array, options?: { copy?: boolean }) { const shuffled = options?.copy ?? true ? [...items] : items; - for (let i = items.length - 1; i > 0; i--) { + for (let i = shuffled.length - 1; i > 0; i--) { const j = await this.uniform(0, i); - [items[i], items[j]] = [items[j], items[i]]; + [shuffled[i], shuffled[j]] = [shuffled[j], shuffled[i]]; } return shuffled;