using System; using System.Globalization; using System.Linq; using System.Collections.Generic; public class Test { public static T[] UniqueRandomArray<T>(T[] input, Random rnd) { if (input.Length <= 1) throw new ArgumentException("Input array must have at least two elements, otherwise the output would be the same.", "input"); IEnumerable<T> rndSeq; while (input.SequenceEqual(rndSeq = input.OrderBy(x => rnd.Next()))); return rndSeq.ToArray(); } public static void Main() { Random rnd = new Random(); List<int[]> randomArrays = new List<int[]>(); int[] arrayInt1 = { 1, 2, 3, 4, 5, 6, 7 }; randomArrays.Add(arrayInt1); for (int i = 0; i < 10; i++) { int[] lastArray = randomArrays[randomArrays.Count - 1]; int[] randomArray = UniqueRandomArray(lastArray, rnd); randomArrays.Add(randomArray); } foreach(int[] array in randomArrays) Console.WriteLine(String.Join(",",array.Select(i=>i.ToString()).ToArray())); } }
Standard input is empty
1,2,3,4,5,6,7 2,7,3,6,1,5,4 6,4,2,3,5,7,1 5,1,4,7,2,3,6 7,4,2,1,6,3,5 2,3,4,7,6,1,5 6,1,4,7,2,5,3 4,2,3,5,1,6,7 2,7,5,3,1,6,4 4,6,1,2,3,5,7 2,3,1,5,7,6,4