Author: spouliot
Date: 2008-02-08 11:40:29 -0500 (Fri, 08 Feb 2008)
New Revision: 95274
Modified:
branches/mono-1-9/mcs/class/corlib/System/ChangeLog
branches/mono-1-9/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)
[Backport r95273]
2008-02-08 Juraj Skripsky <[EMAIL PROTECTED]>
* Random.cs (Next): Use rounding (via implicit conversion) only on
positive values. Fixes bug 359918.
[Backport r95272]
Modified: branches/mono-1-9/mcs/class/corlib/System/ChangeLog
===================================================================
--- branches/mono-1-9/mcs/class/corlib/System/ChangeLog 2008-02-08 16:39:59 UTC
(rev 95273)
+++ branches/mono-1-9/mcs/class/corlib/System/ChangeLog 2008-02-08 16:40:29 UTC
(rev 95274)
@@ -1,3 +1,14 @@
+2008-02-08 Sebastien Pouliot <[EMAIL PROTECTED]>
+
+ * Random.cs: Explain (and extend) special case in Next(min,max)
+ [Backport r95273]
+
+2008-02-08 Juraj Skripsky <[EMAIL PROTECTED]>
+
+ * Random.cs (Next): Use rounding (via implicit conversion) only on
+ positive values. Fixes bug 359918.
+ [Backport r95272]
+
2008-01-25 Rodrigo Kumpera <[EMAIL PROTECTED]>
* MonoType.cs (InvokeMember): Fixed exceptions arguments for last comit.
Modified: branches/mono-1-9/mcs/class/corlib/System/Random.cs
===================================================================
--- branches/mono-1-9/mcs/class/corlib/System/Random.cs 2008-02-08 16:39:59 UTC
(rev 95273)
+++ branches/mono-1-9/mcs/class/corlib/System/Random.cs 2008-02-08 16:40:29 UTC
(rev 95274)
@@ -118,12 +118,13 @@
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;
- int result = (int)(Sample () * diff + minValue);
- return ((result != maxValue) ? result : (result - 1));
+ return (int)(Sample () * diff) + minValue;
}
public virtual void NextBytes (byte [] buffer)
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches