Regarding the Random.Range() method

According the to the Documentation from Unity. It said the min and max value in Random.Range() are both inclusive. if you put 0 and 1 in it, it actually could return 1, which is quite different from some other programming languages (java, javascript, python). Thus I think there is something wrong with one of the quizzes. If you want to generate from 1 to 5 you should put 1 and 5 in the function instead of putting 1 and 6. When you put 1 and 6, it actually can return 6. That’s not what we want. Please share any ideas. Thank you so much!

If you look at the documentation there are 2 entries. One for floats and another for ints. For floats both are inclusive but for integers the max is exclusive. I can’t say that I’ve tested this myself though.

Current Docs

4.6 Docs

1 Like