Author: spouliot
Date: 2008-02-08 11:39:59 -0500 (Fri, 08 Feb 2008)
New Revision: 95273

Modified:
   trunk/mcs/class/corlib/System/ChangeLog
   trunk/mcs/class/corlib/System/Random.cs
Log:
2008-02-08  Sebastien Pouliot  <[EMAIL PROTECTED]>

        * Random.cs: Explain (and extend) special case in Next(min,max)



Modified: trunk/mcs/class/corlib/System/ChangeLog
===================================================================
--- trunk/mcs/class/corlib/System/ChangeLog     2008-02-08 16:29:03 UTC (rev 
95272)
+++ trunk/mcs/class/corlib/System/ChangeLog     2008-02-08 16:39:59 UTC (rev 
95273)
@@ -1,3 +1,7 @@
+2008-02-08  Sebastien Pouliot  <[EMAIL PROTECTED]>
+
+       * Random.cs: Explain (and extend) special case in Next(min,max)
+
 2008-02-08  Juraj Skripsky  <[EMAIL PROTECTED]>
 
        * Random.cs (Next): Use rounding (via implicit conversion) only on

Modified: trunk/mcs/class/corlib/System/Random.cs
===================================================================
--- trunk/mcs/class/corlib/System/Random.cs     2008-02-08 16:29:03 UTC (rev 
95272)
+++ trunk/mcs/class/corlib/System/Random.cs     2008-02-08 16:39:59 UTC (rev 
95273)
@@ -118,8 +118,10 @@
                                throw new ArgumentOutOfRangeException 
(Locale.GetText (
                                        "Min value is greater than max 
value."));
 
-                       uint diff = (uint)(maxValue - minValue);
-                       if (diff == 0)
+                       // special case: a difference of one (or less) will 
always return the minimum
+                       // e.g. -1,-1 or -1,0 will always return -1
+                       uint diff = (uint) (maxValue - minValue);
+                       if (diff <= 1)
                                return minValue;
 
                        return (int)(Sample () * diff) + minValue;

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to