[Mono-bugs] [Bug 359918] New: System.Random.Next(int, int) does not distribute values correctly
bugzilla_noreply at novell.com
bugzilla_noreply at novell.com
Fri Feb 8 08:42:32 EST 2008
https://bugzilla.novell.com/show_bug.cgi?id=359918
Summary: System.Random.Next(int, int) does not distribute values
correctly
Product: Mono: Class Libraries
Version: 1.2.4
Platform: i386
OS/Version: Ubuntu
Status: NEW
Severity: Normal
Priority: P5 - None
Component: System
AssignedTo: mono-bugs at lists.ximian.com
ReportedBy: matthias.krebs at fhnw.ch
QAContact: mono-bugs at lists.ximian.com
Found By: Field Engineer
I have found out that the function System.Random.Next(int, int) does not
distribute the random values in the range it should.
For example: I would like to get random values in a range from -5 to 4, so I
use the function
int x = System.Random.Next(-5, 5);
repeatedly (like a million times).
Now, there should be an approximately uniform distribution from -5 to 4, but
instead I'm always getting a distribution like this:
-5: 0
-4: 1001832
-3: 1000609
-2: 999269
-1: 1000352
0: 1997431
1: 1001696
2: 1000023
3: 998896
4: 999892
5: 0
It is correct that the value 5 never occurs, but there are twice as many
occurrences of 0, but no occurrence of -5.
It also does not matter how big the range is or what the seed is, the lowest
value always gets a count of zero and the "middle" value gets a double count.
I also tested it with .NET 2.0 on Windows, it works as it should there,
therefore I assume there might be a bug in the Mono implementation.
--
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.
More information about the mono-bugs
mailing list