Random number including negatives

Is it possible to use the well-used $(eval Math.floor((Math.random() * 100))) command to give a number anywhere between a negative and a positive number ? (ie. random number between -10 and 10)
Or would it always have to be a positive ?

I’m trying to figure out a command that can give either a number between negative and positive.
If that’s not a thing, I’d like to find a command that could give a positive with 2 different text results, which complicates it even more I think.

Yeah all you have to do is this:

$(eval Math.floor(Math.random()*21)-10)
1 Like

Thanks a lot, still a bit new to Nightbot and I only find posts with positive numbers.

So, far my understanding, in your example you set 21 being the range of possible numbers and -10 being the bottom number ?

Yes the number range for the random numbers is 0-20 and your just subtracting 10 to go to -10 - 10.

The range of Math.floor(Math.random()*N) will always be 0-(N-1)

1 Like

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