/** * Collection.shuffle的实现 i-1 与 rnd.nextInt(i) 交换 * * @param arr object[] */ public static void shuffle1(Object[] arr) { int len = arr.length; for (int i = len; i > 1; i--) swap(arr, i - 1, rnd.nextInt(i)); }
public static void shuffle(Object[] a) { for (int i = 0; i < a.length; i++) { swap(a, i, rnd.nextInt(a.length)); } }