RandomEx to include max?
#1

pawn Код:
public RandomEx(min, max)
{
    return random(max - min) + min;
}
I noticed an issue that this won't include the maximum amount i.e

If I do RandomEx(1, 2) it will only be 1. How can I make it include 2 as well?
Reply
#2

max + 1 when calling the function would solve this but that's how it should actually be. Random will always generate from 0 to max-1
Reply
#3

Ahhhh! I see. That is exactly why! I resolved this issue with that. I couldn't figured out why though, but that's right. Random is from 0! Thank you!
Reply
#4

You should use macro instead public function.

Код:
#define RANDOM(%0,%1) \
	(random(%1-(%0))+%0)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)