Random.Range() not working properly!

So I’m trying to generate a random number between 1 and 4 using Random.Range(1, 4).
For some reason it only generates numbers between 1 and 3! I don’t know why.

This is what I’m using:

int test = Random.Range(1, 4);

It basically ignores the last value which I think is kinda weird because that’s supposed to be the maximum value that CAN be generated. (i think)

From documentation:
Return a random float number between min [inclusive] and max [inclusive] (Read Only).
Return a random integer number between min [inclusive] and max [exclusive] (Read Only).

3 Likes

It’s as designed when using the integer version. It’s to make it easy to select a random element from a list by providing the list length.

1 Like