SA-MP Forums Archive
Random problem. - 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: Random problem. (/showthread.php?tid=226278)



Random problem. - ajwar - 15.02.2011

Hi, i wan't to make 5 random numbers which will not return 0, so: random(5) won't work!


Re: Random problem. - [BEP]AcerPilot - 15.02.2011

What? As I understand your question, random only returns 0 if the random number is 0, if the random number is 125 it returns 125 etc.


Re: Random problem. - PowerPC603 - 15.02.2011

To get a random number from 1 to 5, use this:
pawn Код:
number = random(5) + 1;
The "random(5)" part returns any number from 0 to 4.
Then you simply add 1 to the result, then you get a random number from 1 to 5.

If you need 5 different random numbers, you could use an array to store them for later use:
pawn Код:
new RandomNumbers[5];

for (new i; i < 5; i++)
{
    RandomNumbers[i] = random(1000) + 1;
}
This code creates an array which can hold 5 integer values.
Each index (slot of the array) is filled with a random number between 1 and 1000.