Pull multiple random items from a list

Asked Jan 30, 2022·4 replies·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 command to pull 3 random items from a list and I've seen this code from a developer somewhere else but it doesn't work and i keep getting unexpected errors for identifiers and tokens etc. and I was wondering if anyone could help?

The code I tried is
$(eval a=$(urlfetch json https://pastebin.com/raw/xxxx).split(,); a.pop(); b=[]; for(i=0;i<3;i++){b.push(a.splice(Math.floor(Math.random()*a.length),1));})

I've also tried this without the a.pop() and that won't work either

My pastebin has the following layout:
[ abc,
def,
ghi.]

Thanks

4 replies

Hey @Stellar Bat!

Remove the brackets in your Pastebin, that should fix the issue.

Hi @Polar Cat

Thanks for the reply

I removed the [ ] from my paste bin but now nightbot says there's an unexpected identifier?

I'm not sure what you typed wrong, but you also lack an output. I have no issue with the following code:

$(eval a=`$(urlfetch json https://pastebin.com/raw/XXXXXXXX)`.split(`,`); a.pop(); b=[]; for(i=0;i<3;i++){b.push(a.splice(Math.floor(Math.random()*a.length),1));} b.join(` | `);)

The Pastebin I tested the code on was formatted like so:

abc,
def,
ghi,
jkl,
mno,
pqr,
stu,
vwx,
yza,
Polar Cat said:
$(eval a=$(urlfetch json https://pastebin.com/raw/XXXXXXXX).split(,); a.pop(); b=[]; for(i=0;i<3;i++){b.push(a.splice(Math.floor(Math.random()*a.length),1));} b.join( | );)

This worked!
Thank you