random()
#1

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

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 ;)
Reply
#3

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

thanks
Reply
#4

0 to 9.
Reply
#5

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

gotcha, thanks
Reply
#7

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~
Reply
#8

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)