Pull multiple random items from a list

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

Hey @Trinity!

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

Hi @Emily

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,

This worked!
Thank you

1 Like

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