Java Utililty Methods Array Shuffle

List of utility methods to do Array Shuffle

  1. HOME
  2. Java
  3. A
  4. Array Shuffle

Description

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

Method

T[] randomize(final T[] array)
Reassigns all of the existing values in the given array to different (pseudo-random) slots.
if (array == null) {
 throw (new NullPointerException("passed array is of null value"));
T[] copy = Arrays.copyOf(array, array.length);
List<Integer> track = new ArrayList<Integer>();
for (int i = 0; i < array.length; i++) {
 int rand = -1;
 do {
...
void shuffle()
shuffle
int i;
int j;
int tmp;
int rmd;
Random rnd = new Random();
for (i = 0, j = 0; i < no; i++, j++) {
 seq[j] = 0;
for (i = 0; i < py; i++, j++) {
 seq[j] = 1;
for (i = 0; i < os; i++, j++) {
 seq[j] = 2;
for (i = 0; i < dl; i++, j++) {
 seq[j] = 3;
for (i = 0; i < sl; i++, j++) {
 seq[j] = 4;
for (i = 0, j = total - 1; j > 0; i++, j--) {
 rmd = rnd.nextInt() % (j + 1);
 if (rmd < 0) {
 rmd = rmd * -1;
 tmp = seq[rmd + i];
 seq[rmd + i] = seq[i];
 seq[i] = tmp;
void shuffle(byte[] array)
Randomly shuffle elements within an array.
shuffle(new Random(), array);
void shuffle(byte[] values, Random rnd)
Shuffles the elements in the given array into a random sequence.
shuffle(values, 0, values.length, rnd);
List shuffle(Collection items, Random random)
shuffle
List<T> result = new ArrayList<T>(items);
Collections.shuffle(result, random);
return result;
List shuffle(Collection objects)
Creates a new shuffled list containing the objects in the given collection.
return shuffle(objects, Collections.<T>emptyList());
void shuffle(double[] arr, Random rnd)
Randomly permute the given double array.
for (int i = arr.length - 1; i > 0; i--) {
 int j = rnd.nextInt(i + 1);
 double tmp = arr[i];
 arr[i] = arr[j];
 arr[j] = tmp;
void Shuffle(double[] array)
Shuffle an array.
Shuffle(array, 0);
void shuffle(double[] array, Random r)
Implements Fisher-Yates shuffle.
for (int i = array.length - 1; i > 0; i--) {
 int index = r.nextInt(i + 1);
 double a = array[index];
 array[index] = array[i];
 array[i] = a;
double[][] shuffle(double[][] kernel, long seed)
Shuffle a kernel matrix with seed to initialize the Random object
Double[][] kernelDouble = convert2DoubleObjects(kernel);
for (int i = 0; i < kernel.length; i++) {
 Collections.shuffle(Arrays.asList(kernelDouble[i]), new Random(seed));
Collections.shuffle(Arrays.asList(kernelDouble), new Random(seed));
return convert2DoublePrimitives(kernelDouble);


AltStyle によって変換されたページ (->オリジナル) /