Java Array Shuffle shuffleInPlace(E[] elems, Random rand)

Here you can find the source of shuffleInPlace(E[] elems, Random rand)

Description

shuffle In Place

License

Open Source License

Declaration

public static <E> void shuffleInPlace(E[] elems, Random rand) 

Method Source Code


//package com.java2s;

import java.util.*;

public class Main {
    public static <E> void shuffleInPlace(E[] elems, Random rand) {
        for (int j = elems.length - 1; j > 0; j--) {
            int randIndex = rand.nextInt(j + 1);
            E tmp = elems[randIndex];/*from  w w w.  j a  v  a  2 s . c om*/
            elems[randIndex] = elems[j];
            elems[j] = tmp;
        }
    }
}

Related

  1. shuffleArray(Object[] array)
  2. shuffleArray(T[] ar)
  3. shuffleArray(T[] arr)
  4. shuffled(List list, Random random)
  5. shuffledList(List list)
  6. shuffleInPlace(int[] toShuffle, Random random)
  7. shuffleIntArray(int[] arr)
  8. shuffleIntArray(int[] array)
  9. shuffleList(List list)