fork(1) download
  1. using System;
  2. using System.Globalization;
  3. using System.Linq;
  4. using System.Collections.Generic;
  5.  
  6. public class Test
  7. {
  8. public static T[] UniqueRandomArray<T>(T[] input, Random rnd)
  9. {
  10. if (input.Length <= 1) throw new ArgumentException("Input array must have at least two elements, otherwise the output would be the same.", "input");
  11. IEnumerable<T> rndSeq;
  12. while (input.SequenceEqual(rndSeq = input.OrderBy(x => rnd.Next())));
  13. return rndSeq.ToArray();
  14. }
  15.  
  16. public static void Main()
  17. {
  18. Random rnd = new Random();
  19. List<int[]> randomArrays = new List<int[]>();
  20. int[] arrayInt1 = { 1, 2, 3, 4, 5, 6, 7 };
  21. randomArrays.Add(arrayInt1);
  22.  
  23. for (int i = 0; i < 10; i++)
  24. {
  25. int[] lastArray = randomArrays[randomArrays.Count - 1];
  26. int[] randomArray = UniqueRandomArray(lastArray, rnd);
  27. randomArrays.Add(randomArray);
  28. }
  29. foreach(int[] array in randomArrays)
  30. Console.WriteLine(String.Join(",",array.Select(i=>i.ToString()).ToArray()));
  31. }
  32. }
Success #stdin #stdout 0.05s 34096KB
stdin
Standard input is empty
stdout
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