DbD random Perks

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?

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.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.