From a68d0174f2bd1a756bc2a8be8dd5cc84063dc652 Mon Sep 17 00:00:00 2001 From: Baeck Dong Jae <161856415+VectorSophie@users.noreply.github.com> Date: Fri, 12 Sep 2025 10:08:43 +0900 Subject: [PATCH] pseudorandom.ts minor fixes (#2046) ## Description: in src/core/pseudorandom.ts a helper function of nextint is defined but never used. instead, this.rng is used. those are replaced. also, shuffleArray originally would self-shuffle at i=0 for the conditional being i>=0, fixed to 0. ## Please complete the following: - [X] I have added screenshots for all UI updates - [X] I process any text displayed to the user through translateText() and I've added it to the en.json file - [X] I have added relevant tests to the test directory - [X] I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced ## Please put your Discord username so you can be contacted if a bug or regression is found: jack_45183 --- src/core/PseudoRandom.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/core/PseudoRandom.ts b/src/core/PseudoRandom.ts index d0670ba5f..3a88c7a16 100644 --- a/src/core/PseudoRandom.ts +++ b/src/core/PseudoRandom.ts @@ -36,7 +36,7 @@ export class PseudoRandom { if (arr.length === 0) { throw new Error("array must not be empty"); } - return arr[Math.floor(this.rng() * arr.length)]; + return arr[this.nextInt(0, arr.length)]; } // Selects a random element from a set. @@ -61,14 +61,14 @@ export class PseudoRandom { // Returns true with probability 1/odds. chance(odds: number): boolean { - return Math.floor(this.rng() * odds) === 0; + return this.nextInt(0, odds) === 0; } // Returns a shuffled copy of the array using Fisher-Yates algorithm. shuffleArray(array: T[]): T[] { const result = [...array]; - for (let i = result.length - 1; i >= 0; i--) { - const j = Math.floor(this.rng() * (i + 1)); + for (let i = result.length - 1; i > 0; i--) { + const j = this.nextInt(0, i + 1); [result[i], result[j]] = [result[j], result[i]]; } return result;