[Mono-devel-list] System.Random bug?

Bart Van Rompaey bart at perfectpc.be
Sun Mar 14 16:16:48 EST 2004


I experienced strange behaviour from System.Random when executing the
following piece of code (mono 0.30):

using System;

public class randomtest {
	private const long RANDOM_SEED = 10101010;
	
	public static void Main(string[] args) {
		int i;

		Random R = new System.Random((System.Int32) RANDOM_SEED);
		Console.WriteLine(Int32.MinValue);
		Console.WriteLine(Int32.MaxValue);
		Console.WriteLine();
		for(i = 0; i < 10; i++) {
			Console.WriteLine(R.Next(Int32.MinValue, Int32.MaxValue));
		}
	}
}

The output is as follows:
-2147483648
2147483647
 
-2147483648
-2147483648
-2147483648
-2147483648
-2147483648
-2147483648
-2147483648
-2147483648
-2147483648
-2147483648

However, R.Next() without parameters does provide random numbers, all
positive. A bug?

Bart.


-- 
Bart Van Rompaey <bart at perfectpc.be>




More information about the Mono-devel-list mailing list