Click here to Skip to main content
12,243,721 members (46,148 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

2.7K views
Posted

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

You may also be interested in...

Comments and Discussions

 
GeneralReason for my vote of 1 Very inefficient: Unneeded object c... Pin
Kabwla.Phone11-Oct-11 23:03
memberKabwla.Phone11-Oct-11 23: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.

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