SA-MP Forums Archive
RandomEx to include max? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: RandomEx to include max? (/showthread.php?tid=606830)



RandomEx to include max? - Dokins - 09.05.2016

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?


Re: RandomEx to include max? - Konstantinos - 09.05.2016

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


Re: RandomEx to include max? - Dokins - 09.05.2016

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!


Re: RandomEx to include max? - vannesenn - 09.05.2016

You should use macro instead public function.

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