using System; using System.Collections.Generic; namespace MyProgram { class Program { static Random r = new Random(); static void Main() { List names = new List() {"Mike", "Leanne", "Dave S", "Cindy", "Marianne", "Dave B", "Linda", "Matt", "Lisa", "Dan" }; List picks = new List() { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; while (!IsValid(picks)) { Shuffle(ref picks); } PrintResults(picks, names); } private static void PrintResults(List picks, List names) { for (int i = 0; i < 10; i++) { Console.WriteLine(string.Format("{0} has {1}", names[i], names[picks[i]])); } } private static void Shuffle(ref List picks) { for (int i = 1; i < picks.Count; i++) { //pick random # between 0 and i-1 inclusive int j = r.Next(i); Swap(ref picks, i, j); } } private static void Swap(ref List picks, int i, int j) { int temp = picks[i]; picks[i] = picks[j]; picks[j] = temp; } private static bool IsValid(List picks) { for (int i = 0; i < picks.Count; i++) { if (picks[i] == (i / 2) * 2 || picks[i] == (i / 2) * 2 + 1) return false; } return true; } } }