Java Array Shuffle shuffle(final T[] arr)

Here you can find the source of shuffle(final T[] arr)

Description

shuffle

License

Open Source License

Declaration

public static <T> void shuffle(final T[] arr) 

Method Source Code


//package com.java2s;
import java.util.Random;

public class Main {
    public static <T> void shuffle(final T[] arr) {
        Random rnd = new Random();
        for (int i = arr.length - 1; i > 0; i--) {
            int index = rnd.nextInt(i + 1);
            T tmp = arr[index];// w w w  .  j a  v a 2 s  .  c  o m
            arr[index] = arr[i];
            arr[i] = tmp;
        }
    }
}

Related

  1. shuffle(double[] array, Random r)
  2. shuffle(double[][] kernel, long seed)
  3. shuffle(final A source, final Random random)
  4. shuffle(final Object[] array)
  5. shuffle(final Object[] values)
  6. shuffle(final T[] array)
  7. shuffle(final T[] array)
  8. shuffle(int a[])
  9. shuffle(int arr[])