Random problem.
#1

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

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.
Reply
#3

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)