List of utility methods to do Array Shuffle
A | shuffle(final A source, final Random random) shuffle Collections.shuffle(source, random);
return source;
|
void | shuffle(final Object[] array) shuffle final Random r = new Random(); final int limit = array.length; for (int i = 0; i < limit; ++i) { swap(array, i, r.nextInt(limit)); |
void | shuffle(final Object[] values) shuffle for (int i = 0; i != values.length; i++) { final int r = generator.nextInt(i + 1); swap(values, i, r); |
void | shuffle(final T[] arr) shuffle Random rnd = new Random(); for (int i = arr.length - 1; i > 0; i--) { int index = rnd.nextInt(i + 1); T tmp = arr[index]; arr[index] = arr[i]; arr[i] = tmp; |
T[] | shuffle(final T[] array) Shuffle the elements in the given array. if (array != null && array.length > 0) { final Random random = getRandom(); for (int n = array.length; n > 1;) { final int randomIndex = random.nextInt(n); n--; if (n != randomIndex) { final T tmp = array[randomIndex]; array[randomIndex] = array[n]; ... |
void | shuffle(final T[] array) shuffle shuffle(array, array.length); |
void | shuffle(int a[]) Shuffles (randomizes) the contents of the given array. for (int i = 0; i < a.length - 1; i++) { int tmp = a[i]; int index = i + 1 + random.nextInt(a.length - i - 1); a[i] = a[index]; a[index] = tmp; |
void | shuffle(int arr[]) shuffle Random rnd = r; if (rnd == null) { r = rnd = new Random(); for (int i = arr.length; i > 1; i--) { int nextInt = rnd.nextInt(i); int tmp = arr[i - 1]; arr[i - 1] = arr[nextInt]; ... |
ArrayList | shuffle(int size, boolean reallyShuffle) shuffle ArrayList<Integer> result = new ArrayList<Integer>(); if (reallyShuffle) { HashSet<Integer> shuffled = new HashSet<Integer>(); Random r = new Random(); while (result.size() != size) { int i = r.nextInt(size); if (shuffled.add(i)) { result.add(i); ... |
void | shuffle(int[] a) shuffle for (int i = a.length - 1; i > 0; i--) { int j = rand.nextInt(i + 1); swap(a, i, j); |