Click here to Skip to main content
15,884,472 members
Articles / Programming Languages / C#
Alternative
Tip/Trick

Let's randomize IEnumerable

Rate me:
Please Sign up or sign in to vote.
1.00/5 (1 vote)
10 Oct 2011CPOL 6.3K   1
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;}
C#
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)


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

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

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

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