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

前端 未结 6 2043
我寻月下人不归
我寻月下人不归 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:57

    When you just look in Google for "c# random" and follow the first links to the method of desire you get here: http://msdn.microsoft.com/en-us/library/aa329893(v=vs.71).aspx

    And there is no hint about the exclusiveness of the upper bound. They must have found the mistake in the code and corrected it with documentation.

    So it is important to always check the version of the framework when looking at the documentation. Even when working with old versions of the framework, it is worth to have a look at the newer documentation.

提交回复
热议问题