[Mono-devel-list] System.Random bug?
Sebastien Pouliot
spouliot at videotron.ca
Mon Mar 15 19:34:23 EST 2004
Hello Bart,
> Console.WriteLine(R.Next(Int32.MinValue, Int32.MaxValue));
Good catch. In this case the random part "disappear" because we always add
Int32.MinValue (negative) - so the result can't be anything else than
Int32.MinValue.
return (int)(Sample () * (maxValue - minValue)) + minValue;
> However, R.Next() without parameters does provide random numbers, all
> positive. A bug?
Not in this case. The positive numbers are normal because a call to
R.Next ();
is equivalent to
R.Next (0, Int32.MaxValue);
Thanks for the report. I'll get a look into this.
If possible try to report bugs into bugzilla - just to be sure it doesn't
get lost in the mail during weekends ;-).
Sebastien Pouliot
http://pages.infinit.net/ctech/poupou.html
-----Original Message-----
From: mono-devel-list-admin at lists.ximian.com
[mailto:mono-devel-list-admin at lists.ximian.com]On Behalf Of Bart Van
Rompaey
Sent: 14 mars 2004 16:17
To: mono-devel-list at lists.ximian.com
Subject: [Mono-devel-list] System.Random bug?
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>
_______________________________________________
Mono-devel-list mailing list
Mono-devel-list at lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list
More information about the Mono-devel-list
mailing list