From 4d97bc1ad0af5ca8dc9ebc01987435c83dc37ec0 Mon Sep 17 00:00:00 2001 From: mudkipscience Date: Wed, 22 Apr 2020 16:54:55 +1000 Subject: [PATCH] shuffle command now excluses the first element --- commands/shuffle.js | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/commands/shuffle.js b/commands/shuffle.js index 18edaca..01f02c2 100644 --- a/commands/shuffle.js +++ b/commands/shuffle.js @@ -25,15 +25,13 @@ module.exports.run = (client, message, args, level) => { return message.channel.send('Not enough songs are in the queue for this command to work!') } - let j, x, i - - // Make it so it shuffles all elements EXCEPT [0] - - for (i = queue.length - 1; i > 1; i--) { - j = Math.floor(Math.random() * (i + 1)) - x = queue[i] - queue[i] = queue[j] - queue[j] = x + const max = queue.length - 1 + const min = 1 + for (let i = max; i >= min; i--) { + const randomIndex = Math.floor(Math.random() * (max - min + 1)) + min + const itemAtIndex = queue[randomIndex] + queue[randomIndex] = queue[i] + queue[i] = itemAtIndex } message.channel.send('Queue shuffled!')