Skip to content

Commit 8fa1947

Browse files
committed
Fix random shuffle off-by-one
1 parent f5abc44 commit 8fa1947

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

src/commands/characters/randomteams.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ Replacement characters in case you're missing any: ${chars.slice(8, 14).map(x =>
3737
}
3838

3939
shuffle(input: string[]): string[] {
40-
for (let i = input.length; 0 !== i; i--) {
41-
const rand = Math.floor(Math.random() * (i+1))
40+
for (let i = input.length; i > 0; i--) {
41+
const rand = Math.floor(Math.random() * i)
4242

43-
const tmp = input[i]
44-
input[i] = input[rand]
43+
const tmp = input[i - 1]
44+
input[i - 1] = input[rand]
4545
input[rand] = tmp
4646
}
4747

0 commit comments

Comments
 (0)