import java.util.Arrays; import java.util.Random; class ShuffleIndicies { int[] indicies = range(52); print("Before:", indicies); shuffleArray(indicies); print("After:", indicies); } // Fisher–Yates shuffle public static void shuffleArray(int[] ar) { for (int i = ar.length - 1; i > 0; i--) { int index = r.nextInt(i + 1); int t = ar[index]; ar[index] = ar[i]; ar[i] = t; } } public static final int[] range(int length) { return range(0, length); } public static final int[] range(int start, int length) { int[] range = new int[length - start + 1]; for (int i = start; i <= length; i++) { range[i - start] = i; } return range; } } }
Standard input is empty
Before: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52] After: [4, 2, 20, 19, 9, 5, 28, 7, 36, 25, 48, 43, 38, 11, 47, 41, 0, 33, 31, 16, 21, 40, 17, 27, 52, 15, 44, 34, 6, 14, 22, 37, 32, 39, 50, 26, 10, 35, 46, 13, 24, 3, 23, 45, 12, 8, 42, 18, 1, 29, 49, 30, 51]