Java Utililty Methods Array Shuffle

List of utility methods to do Array Shuffle

Description

The list of methods to do Array Shuffle are organized into topic(s).

Method

int[]shuffle(int[] ary)
shuffle
return shuffle(0, ary, System.currentTimeMillis());
int[]shuffle(int[] input)
Weirdly java doesn't seem to have Arrays.shuffle(), this terrible hack does that.
List<Integer> vals = new ArrayList<Integer>(input.length);
for (int i = 0; i < input.length; i++)
    vals.add(input[i]);
Collections.shuffle(vals, SEEDED_RANDOM);
int[] copy = new int[input.length];
for (int i = 0; i < input.length; i++)
    copy[i] = vals.get(i);
return copy;
...
voidshuffle(int[] list, Random rnd)
shuffle
shuffle(list, list.length, rnd);
voidShuffle(int[] v)
Shuffle an array.
Shuffle(v, v.length);
voidshuffle(Integer[] data)
shuffle
if (data == null)
    return;
Random r = new Random();
for (int i = 0; i < data.length; i++) {
    int n = r.nextInt(data.length);
    int m = r.nextInt(data.length);
    swap(data, n, m);
Listshuffle(List list)
Shuffle list.
Random random = new Random(System.currentTimeMillis());
for (int index = 0; index < list.size() - 1; index += 1) {
    int start = index + 1;
    Collections.swap(list, index, start + random.nextInt(list.size() - start));
return list;
voidshuffle(List list)
shuffle
Collections.shuffle(list);
voidshuffle(List list, Random rnd)
shuffle
if (list instanceof RandomAccess) {
    int size = list.size();
    for (int i = size; i > 1; i--)
        Collections.swap(list, i - 1, rnd.nextInt(i));
Listshuffle(List as)
shuffle
final Random rand = new Random();
return qsort(as, new Comparator<A>() {
    public int compare(A a, A b) {
        return rand.nextInt(3) - 1;
});
Listshuffle(List list)
Shuffle the given list in-place.
Collections.shuffle(list, RANDOM.get());
return list;