Standing on the shoulders of giants. RSS 2.0
# Sunday, November 27, 2005

Update: Still haven't found what is causing the exception, but I think the message of the exception is incorrect. For now I'm sticking with the Knuth Shuffle algorithm from the PowerCollections. As suggested by Cyrus.

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);

}

);

note: This still throws an exception sometimes, claiming x.CompareTo(x) didn't return 0. I haven't found out why this happens or a pattern when this is happening, but I'll keep looking.

Sunday, November 27, 2005 4:10:40 AM (Pacific Standard Time, UTC-08:00)  #    Comments [0] - Trackback
Codesnippet
Comments are closed.
Ads
About
© Copyright 2012
Paul van Brenk
Sign In
newtelligence dasBlog 2.3.2011.0
All Content © 2012, Paul van Brenk
DasBlog theme 'Business' created by Christoph De Baene (delarou)