fork download
  1. using System;
  2.  
  3. public class Test
  4. {
  5. public static int[] RandomIndexes(int size) {
  6. int[] result = new int[size];
  7. for (int i = 0; i < size; i++) {
  8. result[i] = i;
  9. }
  10. ShuffleArray(result);
  11. return result;
  12. }
  13.  
  14. private static Random r = new Random();
  15. public static void ShuffleArray(int [] array) {
  16. for (int i = 0; i < array.Length; i++) {
  17. int j = r.Next(array.Length);
  18. int tmp = array[i];
  19. array[i] = array[j];
  20. array[j] = tmp;
  21. }
  22. }
  23.  
  24. public static void Main()
  25. {
  26. int[] array = RandomIndexes(10);
  27. for (int i = 0; i < array.Length; i++) {
  28. Console.WriteLine(array[i]);
  29. }
  30. }
  31. }
Success #stdin #stdout 0.03s 33856KB
stdin
Standard input is empty
stdout
7
0
3
1
6
9
2
4
5
8