No need to put +1 in Random.Range!


there is no Need to put +1 in the Random.Range!

Because we put the Method OnPressHigher() to min = guess +1 the logic goes that if the guess is 999 and we hit higher the min will go to 1000 and the next guess will therefore be 1000.
So no Need to put Random.Range(min, max+1).

Try it.

And in the case I’m wrong, please tell me. :wink:

1 Like

I literally came on here to say the same thing. I was like, “Wait…the first thing I did was test to be sure it could reach 1000.” Also, if you do put the +1 at the end? Then you can break the upper limit as your minguess exceeds 1000.

You are correct.

I also found that leaving “min = guess + 1;” in OnPressHigher can allow the guess to continue higher than the current max if the user continues to press the “Higher” button even after the guess is correct. To stop this I used the below code in OnPressHigher method:

    if (min < max)
        min = guess + 1;

Seems to work.

Edit: I now see this was mentioned in other posts in this discussion.

Privacy & Terms