using System;
using System.Globalization;
using System.Linq;
using System.Collections.Generic;
public class Test
{
public struct Trio
{
public int Value1 { get; set; }
public int Value2 { get; set; }
public int Value3 { get; set; }
}
public static void Main()
{
List<int> A = new List<int> { 1, 2, 3, 6 };
List<int> B = new List<int> { 4, 5, 6, 8 };
List<int> C = new List<int> { 7, 8, 9, 33 };
var aShuffle = new List<int>(A.Count);
aShuffle.AddRange(A.Shuffle());
var bShuffle = new List<int>(B.Count);
bShuffle.AddRange(B.Shuffle());
var cShuffle = new List<int>(C.Count);
cShuffle.AddRange(C.Shuffle());
List<Trio> trios = new List<Trio>(aShuffle.Count);
for (int i = 0; i < aShuffle.Count; i++)
{
trios.Add(new Trio { Value1 = aShuffle[i], Value2 = bShuffle[i], Value3 = cShuffle[i] });
}
foreach(Trio trio in trios)
Console.WriteLine("Value1: {0} Value2: {1} Value3: {2}", trio.Value1,trio.Value2,trio.Value3);
}
}
public static class Extensions
{
public static IEnumerable<T> Shuffle<T>(this IEnumerable<T> source)
{
return source.Shuffle(new Random());
}
public static IEnumerable<T> Shuffle<T>(this IEnumerable<T> source, Random rng)
{
if (source == null) throw new ArgumentNullException("source");
if (rng == null) throw new ArgumentNullException("rng");
return source.ShuffleIterator(rng);
}
private static IEnumerable<T> ShuffleIterator<T>(
this IEnumerable<T> source, Random rng)
{
List<T> buffer = source.ToList();
for (int i = 0; i < buffer.Count; i++)
{
int j = rng.Next(i, buffer.Count);
yield return buffer[j];
buffer[j] = buffer[i];
}
}
}