Check your understanding Quiz 2.2 question 8 on Randomisation

It asks: Which statement would successfully generate random numbers from the set: 1, 2, 3, 4, 5 ?
Not sure I agree with the answer of Random.Range(1,6); as the arrays start with 0, surely it would be Random.Range(0,4); ?

Hi Lee,

Does the question specifically mention arrays, or was that your interpretation? I think the question is asking which statement will create numbers in this set, e.g. this list of numbers, not referring to a type of structure in the C# language.

Hi Rob,

just as written above so I would expect the array to read:
int[] numberRange = { 1, 2, 3, 4, 5 };
print(numberRange[Random.Range(0, 4)]);
as 1,6 would give the possible answers 2,3,4,5, null and null

Regards,

Lee.

There isn’t a number array though Lee. The questions is just asking which statement would create number available in this series of numbers. The point of the question is to indicate that Random.Range can be used with both floats and integers and it behaves differently depending which are used. Specifically, whether the max value is inclusive or exclusive.

Privacy & Terms