List of utility methods to do Array Shuffle
void | shuffleArray(int[] ar) shuffle Array Random rnd = new Random(); for (int i = ar.length - 1; i > 0; i--) { int index = rnd.nextInt(i + 1); int a = ar[index]; ar[index] = ar[i]; ar[i] = a; |
void | shuffleArray(int[] ar) shuffle Array Random rnd = new Random(); for (int i = ar.length - 1; i >= 0; i--) { int index = rnd.nextInt(i + 1); int a = ar[index]; ar[index] = ar[i]; ar[i] = a; |
void | shuffleArray(int[] ar, Random rnd, int mx) shuffle Array for (int i = mx; i > 0; i--) { int index = rnd.nextInt(i + 1); int a = ar[index]; ar[index] = ar[i]; ar[i] = a; |
void | shuffleArray(int[] arr) shuffle Array int n = arr.length; Random rnd = new Random(); for (int i = 0; i < n; i++) { int tmp = arr[i]; int randomPos = i + rnd.nextInt(n - i); arr[i] = arr[randomPos]; arr[randomPos] = tmp; |
void | shuffleArray(int[] array, int length) Shuffle an array or a portion of an array int index, temp; Random random = new Random(); for (int i = length - 1; i > 0; i--) { index = random.nextInt(i + 1); temp = array[index]; array[index] = array[i]; array[i] = temp; |
void | shuffleArray(int[] array, long rngSeed) shuffle Array shuffleArray(array, new Random(rngSeed));
|
void | shuffleArray(List list) shuffle Array Random rand = new Random(); for (int i = list.size() - 1; i > 0; i--) { int index = rand.nextInt(i + 1); swap(list, index, i); |
void | shuffleArray(Object[] array) shuffle Array shuffleArray(array, new Random());
|
void | shuffleArray(T[] ar) shuffle Array for (int i = ar.length - 1; i > 0; i--) { int index = rnd.nextInt(i + 1); T a = ar[index]; ar[index] = ar[i]; ar[i] = a; |
void | shuffleArray(T[] arr) Permutes the elements of the given array. for (int i = arr.length; i > 1; i--) swap(arr, i - 1, rand.nextInt(i)); |