SA-MP Forums Archive
Setting min-max 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Setting min-max number (/showthread.php?tid=196986)



Setting min-max number - WillyP - 07.12.2010

Hey, I'm sure ****** or someone made a little snippet where you could have a random number being created, but you could set a min/max part. Such as:
pawn Код:
new rand;
rand = random(60000);
//Then a min/max part
So basically what I'm saying is: Can't you do a random timer between something like: 1min and 1min 30 seconds?


Re: Setting min-max number - Mauzen - 07.12.2010

Its not hard, just do it like this:
new rnd = random((MAX_VALUE - MIN_VALUE)) + MIN_VALUE;

or use this define:

#define randommin(%1, %2) random(%1 - %2) + %2


untested


Re: Setting min-max number - WillyP - 07.12.2010

Thanks =D


Re: Setting min-max number - woot - 07.12.2010

This is probably what you have been originally looking for. Had it somewhere laying in an old script ..

pawn Код:
stock minrand(min, max) //By Alex "******" Cole
{
    return random(max - min) + min;
}



Re: Setting min-max number - WillyP - 07.12.2010

Thanks for that too ^^