🤔

Random.Range#

Range with int is [minInclusive..maxExclusive). The upper bound isn't included in the results.

// Always true.
Random.Range(0, 1) == 0

Resolution#

Collections#

array.Length and list.Count are both 1 greater than the bounds of their collection, so they make fantastic limits.

Example#

var value = array[Random.Range(0, array.Length)];

Custom ranges#

Provide Range with the lower bound, and an upper bound + 1.

Example#

// Returns [0..max].
int randomValue = Random.Range(0, max + 1);