Hi everyone! Fairly simple question, I think (I don’t really know much about this kind of stuff).
I was making a command that would send a random twitch clip in chat. You know, highlights from streams, funny moments, etc.
Since I can’t code for shit, I borrowed some formats from my betters and filled in the blanks. Eventually, I got something to work!
My issue is that the code is supposed to throw out a random link from my pastebin, but I get a lot of the same ones. I understand that true randomness is very hard to achieve with computer stuff, but is there maybe a different format I could have used that would have yielded better results?
This is what I used:
$(eval clips = $(urlfetch json https://pastebin.com/raw/Jsy3V5vS).split(","); clips[Math.floor(Math.random() * clips.length)])
The very nature of generating random numbers using
Math.random() means you’ll be getting an even distribution of numbers. That means if you generate a fairly large sample of numbers using this random number generator, each number will appear roughly the same number of times.
This leads to the phenomenon that as you use the random clip command more and more, you will see links being repeated more and more often.
If you provide us another condition for how links should be chosen, perhaps the code can be tweaked further to accomplish what you’re looking for.
Ahh I think I understand that.
Well what I wanted was just for it to be as random as possible.
A dice roll, basically.
Beyond that, I really had no other conditions in mind.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.