DbD random Perks

Asked Oct 6, 2021·1 reply·Last activity 4 years ago·Open in Discord ↗
Archived from the original community forum
Things may have changed since it was written. Still stuck? Ask the community on Discord.

Hi I'm trying to make a bot command to generate 4 random perks for survivor in Dead by Daylight. I already got to this:

$(eval a=$(urlfetch json http://pastebin.com/raw/S6pwgxnB);a[Math.floor(Math.random()*a.length)])

Which results in one of the perks from my list

and this:

$(eval a=$(urlfetch json http://pastebin.com/raw/S6pwgxnB);a[Math.floor(Math.random()*a.length)]) > $(eval a=$(urlfetch json http://pastebin.com/raw/S6pwgxnB);a[Math.floor(Math.random()*a.length)]) > $(eval a=$(urlfetch json http://pastebin.com/raw/S6pwgxnB);a[Math.floor(Math.random()*a.length)]) > $(eval a=$(urlfetch json http://pastebin.com/raw/S6pwgxnB);a[Math.floor(Math.random()*a.length)])

Which is just the same command 4 times.

But these can result in dupes, and I want them all unique, how do I do it?

1 reply

Something like this will work:

`
!commands add !random4 $(eval const a=$(urlfetch json http://pastebin.com/raw/S6pwgxnB);for (let i = a.length - 1; i > 0; i--) {let j = Math.floor(Math.random() * (i + 1));[a[i], a[j]] = [a[j], a[i]];}a.slice(-4).join(", "))
`

Simply randomizing the array and taking the last 4 elements will always produce unique elements.