Random Percentage Glitch? Please Help!

Asked Aug 5, 2024·1 reply·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.

Hi all! I've been combing the internet and reddit etc looking for answers, but no avail. I recently set up this command on my twitch, it seems to be working fine BUT nobody gets 100% ... We had 3 streams, my chat was spamming the command and not a single person got 100%. I tried spamming the command as well and nothing. We have over 20 people in chat all using it for multiple streams and no nobody got 100%

$(touser) is $(eval Math.floor((Math.random() * 100)))% sweet!

That's the code, is there something I can tweak or change to make the chance of 100% a possibility? Or did I code this wrong?

Thank you so much in advance for your help :)

1 reply

This is where all the numeric representation nerds have a chance to shine!

Short answer:
You can get values 0-100, including both 0 and 100, with
$(touser) is $(eval Math.floor((Math.random() * 101)))% sweet!

Longer answer:

From some Javascript docs:

The Math.random() static method returns a floating-point, pseudo-random number that's greater than or equal to 0 and less than 1

That means that a generated number can be incredibly close to 1, but will always be slightly smaller. The rest of the code multiplies that value by 100 and rounds down, which gets you a number slightly less than 100 (and then rounds down to the nearest whole number). That's why you aren't seeing any perfect 100%s from the command.