Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static IEnumerable<TSource> Shuffle<TSource>(this IEnumerable<TSource> source) {
- List<TSource> list = source.ToList();
- Random random = new Random();
- for (int i = list.Count - 1; i >= 0; i--) {
- int r = random.Next(i + 1);
- yield return list[r];
- list[r] = list[i];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment