Home Dashboard Directory Help
Search

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


Status: 

Closed
 as By Design Help for as By Design


1
0
Sign in
to vote
Type: Bug
ID: 730666
Opened: 3/12/2012 8:46:21 AM
Access Restriction: Public
Moderator Decision: Sent to Engineering Team for consideration
0
Workaround(s)
view
0
User(s) can reproduce this bug

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.
Details
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)
Sign in to post a workaround.