[HELP] Random numbers? - 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)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: [HELP] Random numbers? (
/showthread.php?tid=90645)
[HELP] Random numbers? -
SiJ - 09.08.2009
Hey,
How could I make that it would randomaly pick number from like 500 to 1000 ? If I do random(1000) it will pick from 0 to 1000...
Re: [HELP] Random numbers? -
WrathOfGenesis - 09.08.2009
You want a minimum of 500 and a max of 1000. The difference between the numbers is 500 so do:
or use
pawn Код:
stock RandomMinMax ( min , max )
{
return random ( max - min ) + min;
}
Re: [HELP] Random numbers? -
dice7 - 09.08.2009
Quote:
Originally Posted by WrathOfGenesis
pawn Код:
stock RandomMinMax ( min , max ) { return random ( max - min ) + min; }
|
pawn Код:
stock RandomMinMax ( min , max ) return random ( max - min +1 ) + min;
Re: [HELP] Random numbers? -
SiJ - 09.08.2009
Thanks
Re: [HELP] Random numbers? -
WrathOfGenesis - 09.08.2009
Why + 1?
That means if the lowest value is 0 and the highest is 5 it can return 6.
Re: [HELP] Random numbers? -
bogeymanEST - 09.08.2009
The random(max) function chooses a number between 0 and max-1 (from Pawn_Language_Guide.pdf)
Re: [HELP] Random numbers? -
WrathOfGenesis - 09.08.2009
Checked my randomminmax function in my script and your right. My mistake