import java.util.Arrays; import java.util.Random; /* There is normally no need to write shuffle. There is a static method void Collections.shuffle (List list, Random rng) in the java.util.Collections class, but not one in java.util.Arrays. In the case of an array one can use: List Arrays.asList(T... a) */ public final class GenericShuffle { private static final Random RNG = new Random (Long.getLong ("seed", System.nanoTime())); // Randomly permute the elements of the array 'x' public static void shuffle (final T[] x) { final int n = x.length; for (int i = 0; i