Pick 2 "different" random lines with urlfetch?

Asked May 23, 2024Β·3 repliesΒ·Last activity 2 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.

Heya all πŸ™‚

I have a timer that gives shoutouts to 2 streamers from my clan every so often. At the moment it just picks a random line from a file twice, but that does sometimes pick the same line twice.

imGlitch imGlitch Why not follow $(eval a=`$(urlfetch json https://zoeballz.tv/nb/REBORN.txt)`.split(`#`);a[Math.floor(Math.random()*a.length)]) and $(eval a=`$(urlfetch json https://zoeballz.tv/nb/REBORN.txt)`.split(`#`);a[Math.floor(Math.random()*a.length)]) who are World of Tanks streamers and members of REBORN :) imGlitch imGlitch

Is there a simple way within the command line to make sure it doesn't shoutout the same person twice please ? Or do I need to write an API to do it ?
(I don't know JS !)

Many thanks,

Zoe

3 replies

It is possible to avoid repeats with JS, using the splice function to remove the first streamer from the list after they have been chosen:

imGlitch imGlitch Why not follow $(eval a=`$(urlfetch json https://zoeballz.tv/nb/REBORN.txt)`.split(`#`);x1=a.splice(Math.floor(Math.random()*a.length), 1)[0];x2=a[Math.floor(Math.random()*a.length)];x1 + " and " + x2) who are World of Tanks streamers and members of REBORN :) imGlitch imGlitch

This also has the advantage of only loading the text file once! Hope it works well for you

Thanks so much πŸ™‚

Seems to run fine :star_struck:

I'll have to work out JS one day. Still getting to grips with PHP atm !!