random(integer) - 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: random(integer) (
/showthread.php?tid=518214)
random(integer) -
AnonScripter - 08.06.2014
pawn Код:
if(numrand == 0)
{
numrand += 0;
}
if i don't want number "0" includes the random do i put "+= 0" or "+= 1"
Re: random(integer) -
SilentSoul - 08.06.2014
You should do the random number +1 like you did but in other way,
pawn Код:
new rand = random(5)+1; // now if the random was 0 it will be +1 so it would be one and always ignores the zero
Another way to do this
pawn Код:
stock randomEx(min, max)
{
//Credits to ******
new rand = random(max-min)+min;
return rand;
}
new rand = randomEx(1,3)l//from one to three
Re: random(integer) -
Konstantinos - 08.06.2014
By doing "+= 1" will add + 1 to the variable (which was 0) so numrand will be 1.
Well, you can use min-max values for randoms if you want:
pawn Код:
stock RandomEx(min, max)
{
return random(max - min) + min;
}
Re: random(integer) -
AnonScripter - 08.06.2014
max = 5. min = 1
5 -1 = 4
4+ 1 = 5
so this is the same of random(5)
Re: random(integer) -
Koala818 - 08.06.2014
Quote:
Originally Posted by AnonScripter
max = 5. min = 1
5 -1 = 4
4+ 1 = 5
so this is the same of random(5)
|
it's random(min, max);
so min=1 max=5
random(5-1)+1=random(4)+1
so if you'l get 0 it will actually be 1 and if you get 3 it will actually be 4
Re: random(integer) -
AnonScripter - 08.06.2014
what if u get 4 ?
4 +1 =5
Re: random(integer) -
Koala818 - 08.06.2014
random(i) will return a random value from 0 to i-1 so you can't get 4.
https://sampwiki.blast.hk/wiki/Random
Re: random(integer) -
Konstantinos - 08.06.2014
The isn't a way to get 4. randon(4) will give a number between 0 and 3. So the result (for min 1 and max 5) will be 1, 2, 3, 4
Re: random(integer) -
AnonScripter - 08.06.2014
so explain this please:
RandomEx(1,50);
50 - 1 = 49
random(49);
if it will not choose 49, so it will choose 48
48+1 = 49
so 50 is out ?
Re: random(integer) -
Koala818 - 08.06.2014
Yes. RandomEx posted upper gets a random number from [min, max-1]