MS Visual C# 2010 Express bug in Random number generator - by watsonchan

Status : 

  By Design<br /><br />
		The product team believes this item works according to its intended design.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.


1
0
Sign in
to vote
ID 730666 Comments
Status Closed Workarounds
Type Bug Repros 0
Opened 3/12/2012 8:46:21 AM
Access Restriction Public
Moderator Decision Sent to Engineering Team for consideration

Description

In MS Visual C# 2010 Express, when I use the Random number generator, it does not generate the maximum number itself given in the range.  For example:

  Random r = new Random();
  int randNum = r.Next(1, 12);  // randNum gets a number between 1 - 11 but never gets 12.
   ...
  randNum = r.Next(1,60);        // randNum gets a number between 1 - 59 but never gets 60.
Sign in to post a comment.
Posted by Microsoft on 3/16/2012 at 10:39 AM
The behavior you described is by design. From the documentation on MSDN (http://msdn.microsoft.com/en-us/library/2dx6wyd4.aspx):

Return Value
Type: System.Int32
A 32-bit signed integer greater than or equal to minValue and less than maxValue; that is, the range of return values includes minValue but not maxValue. If minValue equals maxValue, minValue is returned.

Thanks for using the .NET Framework.

Weitao Su
Microsoft Corp.
Posted by MS-Moderator09 [Feedback Moderator] on 3/12/2012 at 10:17 PM
Thanks for your feedback. We are routing this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.Thank you !
Posted by MS-Moderator01 on 3/12/2012 at 9:47 AM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)