I thought I completely understood how to do this. It seems pretty straight forward. However when taking the knowledge quiz I missed it. I thought it worked on an array unless a range was specified. It looks like an array in our Hacker program. The example on Udemy seems to show the same thing. However the correct response on the quiz does not start at zero. It starts with 1. Can someone clarify please?
Hi Andrew,
The question is: “Which statement would successfully generate random numbers from the set: 1, 2, 3, 4, 5?” That’s the task.
Since the min value that is passed on to the Random.Range method is inclusive, the first argument is 1 instead of 0.
The question did not mean: “Which statement would successfully generate random numbers from the array: 1, 2, 3, 4, 5?”
If that was the question, 0 as the first argument would have been correct.
Did this clear it up for you?
Maybe. Let me rephrase… The question was not intended to test completeness of Random.Range but more so to find out if we understood the inclusive AND exclusive of it. Correct? If so then I am all set.
Exactly. The “problem” with the Random.Range method is that there are two versions. If you are not careful when looking it up in the API, you can easily make a mistake by thinking the max parameter of the int version was inclusive, too. That’s all the question wanted to test.
Thank you. I missed the intent of the question and then was confused. This made it completely clear.
This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.