Nick Johnson2,345 Points
Why, when setting the upper bound for the random number generator, do we not have to do colors.count - 1?
Maybe I'm wrong in thinking colors.count == 7 (in this particular case). But if that is the case, if we were to return colors, wouldn't that cause an out of bounds error?
Jennifer NordellTreehouse Staff
Hi there! You're right, it would. However, the
nextInt returns a number between 0(inclusive) and the upperBound number (exclusive). So, in this case you will only ever get the numbers 0-6 as 7 is not included.
Here's some documentation
This is simply how the upperBound in the
Hope this helps!