Random Number
#7

Quote:
Originally Posted by [XST]O_x
Посмотреть сообщение
If you want to randomize between a minimal and a maximal number you can use randomex:
pawn Код:
stock randomex(min, max)
{
    return random(max - min) + min;
}
For example:
random(5) can return 0,1,2,3,4,5 while randomex(3,5) can return 3,4,5.
Why would you use a stock for that? It's quite a lot slower than using a define.

pawn Код:
#define randomex(%1,%2) random(%1 - %2) + %2
Also, 1 - 100 can simply be done by
pawn Код:
new randomnum = random(100) + 1;
//Numbers start at 0 and would go to 99 but we added the +1 so it went from 1 -> 100.
Reply


Messages In This Thread
Random Number - by FreeSoul - 21.01.2012, 20:40
Re: Random Number - by Konstantinos - 21.01.2012, 20:41
Re: Random Number - by [XST]O_x - 21.01.2012, 20:48
Re: Random Number - by Konstantinos - 21.01.2012, 20:52
Re: Random Number - by [XST]O_x - 21.01.2012, 20:54
Re: Random Number - by Chris White - 21.01.2012, 21:00
Re: Random Number - by [HiC]TheKiller - 21.01.2012, 21:36
Re: Random Number - by Gh05t_ - 21.01.2012, 21:50
Re: Random Number - by Macluawn - 21.01.2012, 21:51
Re: Random Number - by [HiC]TheKiller - 21.01.2012, 22:04

Forum Jump:


Users browsing this thread: 3 Guest(s)