random(integer)
#1

pawn Код:
if(numrand == 0)
        {
            numrand += 0;
        }
if i don't want number "0" includes the random do i put "+= 0" or "+= 1"
Reply
#2

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
Reply
#3

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;
}
Reply
#4

max = 5. min = 1
5 -1 = 4
4+ 1 = 5

so this is the same of random(5)
Reply
#5

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
Reply
#6

what if u get 4 ?
4 +1 =5
Reply
#7

random(i) will return a random value from 0 to i-1 so you can't get 4.

https://sampwiki.blast.hk/wiki/Random
Reply
#8

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
Reply
#9

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 ?
Reply
#10

Yes. RandomEx posted upper gets a random number from [min, max-1]
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)