Click here to Skip to main content
Click here to Skip to main content
Alternative Tip/Trick

Tagged as

Let's randomize IEnumerable

, 10 Oct 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
public static IEnumerable randomize(this IEnumerable source) { var y = (from s in source select new { n = myrandomeImpl.Next(), v = s }).OrderBy(f => f.n); foreach (var item in y) yield return item.v;}
public static IEnumerable<T> randomize<T>(this IEnumerable<T> source) {
    var y = (from s in source select new { n = myrandomeImpl.Next(), v = s }).OrderBy(f => f.n);
    foreach (var item in y)
        yield return item.v;
}

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

cechode

United States United States
No Biography provided

Comments and Discussions

 
GeneralReason for my vote of 1 Very inefficient: Unneeded object c... PinmemberKabwla.Phone11-Oct-11 22:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.141030.1 | Last Updated 10 Oct 2011
Article Copyright 2011 by cechode
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid