SA-MP Forums Archive
How to make a random number that won't go less than 10000 or higher than 40000? - 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: How to make a random number that won't go less than 10000 or higher than 40000? (/showthread.php?tid=477526)



How to make a random number that won't go less than 10000 or higher than 40000? - jueix - 24.11.2013

Ok the title basicly says all, Its been along time since I played around with randomizing numbers and can't rember how to do it.

For example in my script I have this code.

pawn Код:
RobberieInfo[MaxRobLimit] = 40000
RobberieInfo[MinRobLimit] = 10000
I was wondering how I can use them variables and make it pick a random number between them?


Re: How to make a random number that won't go less than 10000 or higher than 40000? - Konstantinos - 24.11.2013

pawn Код:
stock RandomEx(min, max) //******
{
    return random(max - min) + min;
}
pawn Код:
// Usage:
new random_number = RandomEx(RobberieInfo[MinRobLimit], RobberieInfo[MaxRobLimit]);



Re: How to make a random number that won't go less than 10000 or higher than 40000? - RajatPawar - 24.11.2013

EDIT: Late, nvm.
pawn Код:
stock random_between(min, max) { return (min + random(max - min));  }
Use this!


Re: How to make a random number that won't go less than 10000 or higher than 40000? - jueix - 24.11.2013

Thanks guys.