C# Random.Next - never returns the upper bound?

前端 未结 6 2006
我寻月下人不归
我寻月下人不归 2020-12-04 15:06
random.Next(0,5)

It never returns the 5 (but sometimes returns the 0.) Why? I thought these are just boundary values that can be returned. Thanks

6条回答
  •  一生所求
    2020-12-04 15:37

    Good way to remember it is to consider max as amount of numbers from which it takes random number. So random.Next(0,2) means that it takes random out of 2 numbers starting from 0: 0 and 1.

提交回复
热议问题