Java Array Shuffle shuffle(T[] data)

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

Description

shuffle

License

Open Source License

Declaration

public static <T> void shuffle(T[] data) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.Random;

public class Main {
    private static final Random RandomInstance = new Random();

    public static <T> void shuffle(T[] data) {
        int n = data.length;
        int n1 = n - 0x01;
        T tmp;/*  www. j a v a 2  s  . c om*/
        for (int i = 0x00; i < n1; i++) {
            tmp = data[i];
            int j = nextInt(n1 - i) + i;
            data[i] = data[j];
            data[j] = tmp;
        }
    }

    public static int nextInt() {
        return RandomInstance.nextInt();
    }

    public static int nextInt(int n) {
        return RandomInstance.nextInt(n);
    }
}

Related

  1. shuffle(T[] array)
  2. shuffle(T[] array)
  3. shuffle(T[] array, Random rand)
  4. shuffle(T[] array, Random rand)
  5. shuffle(T[] array, Random random)
  6. shuffleArray(double[] ar)
  7. shuffleArray(int arr[])
  8. shuffleArray(int[] a)
  9. shuffleArray(int[] ar)