Java Array Shuffle shuffleIntArray(int[] array)

Here you can find the source of shuffleIntArray(int[] array)

Description

shuffle Int Array

License

Open Source License

Declaration

static int[] shuffleIntArray(int[] array) 

Method Source Code


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

public class Main {

    static int[] shuffleIntArray(int[] array) {
        int[] copy = array.clone();
        Random rnd = new Random();
        for (int i = copy.length - 1; i > 0; i--) {
            int index = rnd.nextInt(i + 1);
            // Simple swap
            int a = copy[index];
            copy[index] = copy[i];//from   w w w . j a v a  2s .  com
            copy[i] = a;
        }
        return copy;
    }
}

Related

  1. shuffled(List list, Random random)
  2. shuffledList(List list)
  3. shuffleInPlace(E[] elems, Random rand)
  4. shuffleInPlace(int[] toShuffle, Random random)
  5. shuffleIntArray(int[] arr)
  6. shuffleList(List list)
  7. shuffleList(List list)
  8. shuffleSublist(List objects, int start, int end)