SA-MP Forums Archive
random() - 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() (/showthread.php?tid=66871)



random() - Kinetic - 25.02.2009

if I had random(10); does the function return a random number from 1 to 10 or from 0 to 10?


Re: random() - JaYmE - 25.02.2009

0 - 10

and you need to make it defined

pawn Код:
new MyRand = random(10);

MyRand += 1;

// then you can use the random and it should be 1 - 10 not 0 - 10 ;)



Re: random() - Kinetic - 25.02.2009

No wonder the script is creating car model 0 sometimes :P

thanks


Re: random() - yom - 25.02.2009

0 to 9.


Re: random() - JaYmE - 25.02.2009

Quote:
Originally Posted by 0rb
0 to 9.
Oooooooops i made a really nooby mistake


Re: random() - Kinetic - 25.02.2009

gotcha, thanks


Re: random() - Cueball - 25.02.2009

A way to think of random() is that the 'max' paramater you input is the amount of possible values returned. For example:


INPUT
POSSIBLE OUTPUTS


1
0


2
0, 1


3
0, 1, 2


4
0, 1, 2, 3



Notice how the input value is the amount of possible outputs, so using that you can figure out that a 'max' of 10 will give you 10 possible outputs, and because they can not be negative and start at 0, they must be 0 through to 9.

Hope it helps

~Cueball~



Re: random() - mamorunl - 25.02.2009

Quote:
Originally Posted by JaYmE
0 - 10

and you need to make it defined

pawn Код:
new MyRand = random(10);

MyRand += 1;

// then you can use the random and it should be 1 - 10 not 0 - 10 ;)
you dont HAVE to.

ex:

pawn Код:
CreateVehicle(random(400) + 200), 203, 203, 102, 22, -1, -1, -1);
this way, it isnt defined