15.02.2011, 17:06
To get a random number from 1 to 5, use this:
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:
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.
pawn Код:
number = random(5) + 1;
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;
}
Each index (slot of the array) is filled with a random number between 1 and 1000.