ArrayUtil { public static void shuffle(double[] arr) { val rnd = ThreadLocalRandom.current(); for (int i = arr.length - 1; i > 0; i--) { val index = rnd.nextInt(i + 1); val elemToSwap = arr[index]; arr[index] = arr[i]; arr[i] = elemToSwap; } }  static void shuffle(double[] arr);  }
@Test public void testShuffle() { val n = 14; val orig = new double[n]; for (int i = 0; i < n; i++) { orig[i] = i; } val copy = Arrays.copyOf(orig, n); ArrayUtil.shuffle(copy); int diffCount = 0; for (int i = 0; i < n; i++) { if (orig[i] != copy[i]) { diffCount++; } } assertTrue(diffCount > 0); Arrays.sort(copy); assertArrayEquals(orig, copy, TOLERANCE); }