List of utility methods to do Array Shuffle
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; ... |
void | shuffle(int[] list, Random rnd) shuffle shuffle(list, list.length, rnd); |
void | Shuffle(int[] v) Shuffle an array. Shuffle(v, v.length); |
void | shuffle(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); |
List> | shuffle(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; |
void | shuffle(List> list) shuffle Collections.shuffle(list); |
void | shuffle(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)); |
List | shuffle(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; }); |
List | shuffle(List Shuffle the given list in-place. Collections.shuffle(list, RANDOM.get());
return list;
|