randomize a pagedatacollection

Hi all I'm trying to randomize the content of a pagedatacollection and was wondernig if there is a sorter for this already, i.e FilterPropertySort or something alike. Or maybe put it all in an arraylist and randomize that one? Any suggestions?
Aug 15, 2007 10:25
Well, since I figured it out (which was quite simple btw) I might aswell post it here and it might help someone out :) for (int i = 0; i < yourPageDataCollectionObject.Count; i++) { PageData x = yourPageDataCollectionObject[i]; Random rng = new Random(); int index = rng.Next(yourPageDataCollectionObject.Count - i) + i; yourPageDataCollectionObject[i] = yourPageDataCollectionObject[index]; yourPageDataCollectionObject[index] = x; }
Aug 15, 2007 13:49

That code save me a lot of time, thanks! I did however have some trouble with some objects that as good as always seemed to get the same position after the randomization. I got the a tip in another thread to move the initializing of the Random class outside the loop and that solved it.

Dec 15, 2009 16:47
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.