Random.Range Problem

I have the code:

var r = Random.Range(0,1);

function Update(){
Print(r);
}

But it ALWAYS gives me the number ‘0’.

I dont understand why it wont give me a random range between 0 and 1.

Anyone help??

Thanks.

Take a look at the docs, paying attention to the section describing what happens when you use integers.

–Eric

But i get the samew problem from the code:

var r : float = Random.Range(0,1);

function Update(){
Print(r);
}

Because it’s doing exactly the same thing. What matters is the numbers you’re using in Random.Range, not the variable you’re assigning the result to.

–Eric

Ahh I think I understand.

Random.Range(0.00,1.00);

Should do the trick.

Yes, or Random.Range(0,2);

You can also use

Random.Range(0f, 1f)