Random
#1

What was the code responsible for picking up a random number between numbers?
Reply
#2

Search forum. This was answered billion times.
Reply
#3

random()
pawn Код:
new RandomNumber = random(500);
print( RandomNumber );
That will print a number between 0-500
Reply
#4

random(number);

Ex:
pawn Код:
rand = random(3);
switch(rand)
{
    case 0: Blah Blah;
    case 1: Blah Blah;
    case 2: Blah Blah;
}
EDIT: I'm tad late...
Reply
#5

Quote:
Originally Posted by Wesley221
Посмотреть сообщение
random()
pawn Код:
new RandomNumber = random(500);
print( RandomNumber );
That will print a number between 0-500
Wrong. 0-499

Thanks for your help guys anyway

I searched and it said Rand at some places, so I wanted to make sure
Reply
#6

If you want to get numbers between a certain x digit and a certain y digit, you can add this to the bottom of your script:

pawn Код:
// credit to KyleSmith
stock randomEx(minnum = cellmin, maxnum = cellmax)
{
    return random(maxnum - minnum + 1) + minnum;
}
Then use it to get random lotto numbers for example:

pawn Код:
new lotto = randomEx(1,100); // will pick a random number between 1 and 100
Or for a simple cash payout, between 10,000 and 20,000:

pawn Код:
new payout = randomEx(10000,20000); // will choose a random amount between 10k to 20k
GivePlayerMoney(playerid,payout); // give the player the random cash payout
print(payout); // print the random cash payout
Reply
#7

I already know that

I'll tell you something. I started scripting just few weeks ago, but it seems very easy for me

The main reason is that I know C

Thanks for everyone for help anyway
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)