Random number .......... - 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 number .......... (
/showthread.php?tid=354815)
Random number .......... -
PaulDinam - 28.06.2012
I made a fish system so how can i know what numbers it can be from that code:
new randf = random(25)+15;
with this code when i do /fish it's usually gives me between 15-27
I want to make it betweeb 10-35
Re: Random number .......... -
ReneG - 28.06.2012
Use this stock function.
pawn Код:
stock randomEx(min, max)
{
new rand = random(max-min)+min;
return rand;
}
Here is how you would use it in code.
pawn Код:
new randf = randomEx(10, 35);
Re: Random number .......... -
JaTochNietDan - 28.06.2012
Quote:
Originally Posted by VincentDunn
Use this stock function.
pawn Код:
stock randomEx(min, max) { new rand = random(max-min)+min; return rand; }
Here is how you would use it in code.
pawn Код:
new randf = randomEx(10, 35);
|
No point in that memory allocation by the way (of "rand"), you could just shorten the whole function to this:
pawn Код:
stock randomEx(min, max) return random(max-min) + min;
A small change, but avoiding unnecessary memory allocation and redundant code