[Mono-bugs] [Bug 79858][Wis] Changed - Random.Next() returns negative numbers

bugzilla-daemon at bugzilla.ximian.com bugzilla-daemon at bugzilla.ximian.com
Tue Nov 7 06:48:12 EST 2006


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by nicola at dinosoft.it.

http://bugzilla.ximian.com/show_bug.cgi?id=79858

--- shadow/79858	2006-11-07 06:26:18.000000000 -0500
+++ shadow/79858.tmp.11191	2006-11-07 06:48:12.000000000 -0500
@@ -1,12 +1,12 @@
 Bug#: 79858
 Product: Mono: Class Libraries
 Version: 1.1
 OS: unknown
 OS Details: Gentoo 2006.1 (kernel 2.6.18)
-Status: NEEDINFO   
+Status: CLOSED   
 Resolution: 
 Severity: Unknown
 Priority: Wishlist
 Component: System
 AssignedTo: mono-bugs at ximian.com                            
 ReportedBy: nicola at dinosoft.it               
@@ -46,6 +46,31 @@
 for (int i=0; i<100; i++)
   Console.WriteLine("rand: {0}", r.Next());
         }
 }
 
 Maybe you could provide the complete repro code?
+
+------- Additional Comments From nicola at dinosoft.it  2006-11-07 06:48 -------
+I'm very sorry, there's nothing wrong with Random.Next().
+I promise next time I will pay way more attention. :)
+Nevertheless, please try the following:
+
+using System;
+
+public class Test
+{
+   public static void Main ()
+   {
+     Random r = new Random();
+     for (int i=0; i<100; i++)
+       Console.WriteLine("rand: {0}", (r.Next()*r.Next()) % 2);
+   }
+}
+
+This time (for real) I get 1 and -1
+But x % 2 can't be -1 !
+Why this ?
+If it would be so because of we get out of integer boundaries,
+I would expect I at least an exception to be thrown, no ?
+
+


More information about the mono-bugs mailing list