P
Paul van Brenk
When you run the Shuffle[0] method often enough it will throw exception[1].
And I can't figure out why.
Anybody?
Paul van Brenk
[0] the code:
static void Shuffle(){
int[] ints = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
System.Random rand = new System.Random((int)DateTime.Now.Ticks);
Array.Sort(ints, delegate(int x, int y){
// since you're not allowed to return anything else than 0 for
x.CompareTo(x)
if (x == y) {
return 0;
}
return rand.Next(-1,2);
}
);
}
[1] the exception:
exc.Message "IComparer (or the IComparable methods it relies upon) did not
return zero when Array.Sort called x. CompareTo(x). x: '5' x's type:
'Int32' The IComparer: 'System.Array+FunctorComparer`1[System.Int32]'."
And I can't figure out why.
Anybody?
Paul van Brenk
[0] the code:
static void Shuffle(){
int[] ints = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
System.Random rand = new System.Random((int)DateTime.Now.Ticks);
Array.Sort(ints, delegate(int x, int y){
// since you're not allowed to return anything else than 0 for
x.CompareTo(x)
if (x == y) {
return 0;
}
return rand.Next(-1,2);
}
);
}
[1] the exception:
exc.Message "IComparer (or the IComparable methods it relies upon) did not
return zero when Array.Sort called x. CompareTo(x). x: '5' x's type:
'Int32' The IComparer: 'System.Array+FunctorComparer`1[System.Int32]'."