random number between two numbers
#1

I've seen on wiki the random function but it only has the "max" parameter, so it would generate a number between 0 and "max-1".

how can I generate a random number between two numbers? Like 5 and 10.... it would generate 5, 6, 7, 8, 9 or 10.
Reply
#2

Like this?
pawn Код:
stock randomEx(min, max)
{    
    //Credits to ******    
    new rand = random(max-min)+min;    
    return rand;
}
Reply
#3

Quote:
Originally Posted by Fj0rtizFredde
Посмотреть сообщение
Like this?
pawn Код:
stock randomEx(min, max)
{    
    //Credits to ******    
    new rand = random(max-min)+min;    
    return rand;
}
hm
looks nice, lol, thanks
I would use like this?
Код:
new A = randomEx(5,10);
And, it would generate 5 and 10 or only 6, 7, 8 and 9?
Reply
#4

Yes use it like that And Im not sure about if its 5-9 or 5-10 cant remember :/ Try it and you will find out
Reply
#5

It would generate 5-9
Reply
#6

ok thank you all
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)