Reorder An Array Randomly
Java:
static void shuffle(T[] a) {
Random r = new Random();
for (int i = a.length; i > 1; --i) {
int j = r.nextInt(i);
T t = a[i - 1];
a[i - 1] = a[j];
a[j] = t;
}
}
Java:
static void shuffle(T[] a) {
Random r = new Random();
for (int i = a.length; i > 1; --i) {
int j = r.nextInt(i);
T t = a[i - 1];
a[i - 1] = a[j];
a[j] = t;
}
}