shuffle command now excluses the first element

This commit is contained in:
Emily 2020-04-22 16:54:55 +10:00
parent 6d5d476528
commit 4d97bc1ad0

View file

@ -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!') return message.channel.send('Not enough songs are in the queue for this command to work!')
} }
let j, x, i const max = queue.length - 1
const min = 1
// Make it so it shuffles all elements EXCEPT [0] for (let i = max; i >= min; i--) {
const randomIndex = Math.floor(Math.random() * (max - min + 1)) + min
for (i = queue.length - 1; i > 1; i--) { const itemAtIndex = queue[randomIndex]
j = Math.floor(Math.random() * (i + 1)) queue[randomIndex] = queue[i]
x = queue[i] queue[i] = itemAtIndex
queue[i] = queue[j]
queue[j] = x
} }
message.channel.send('Queue shuffled!') message.channel.send('Queue shuffled!')