Java Array Shuffle shuffleArray(List list)

Here you can find the source of shuffleArray(List list)

Description

shuffle Array

License

Open Source License

Declaration

public static void shuffleArray(List list) 

Method Source Code


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

import java.util.List;
import java.util.Random;

public class Main {
    public static void shuffleArray(List list) {
        Random rand = new Random();
        for (int i = list.size() - 1; i > 0; i--) {
            int index = rand.nextInt(i + 1);
            swap(list, index, i);/*w ww. j av a  2s.co m*/
        }
    }

    public static void swap(List list, int indexA, int indexB) {
        Object temp = list.get(indexA);
        list.set(indexA, list.get(indexB));
        list.set(indexB, temp);
    }
}

Related

  1. shuffleArray(int[] ar)
  2. shuffleArray(int[] ar, Random rnd, int mx)
  3. shuffleArray(int[] arr)
  4. shuffleArray(int[] array, int length)
  5. shuffleArray(int[] array, long rngSeed)
  6. shuffleArray(Object[] array)
  7. shuffleArray(T[] ar)
  8. shuffleArray(T[] arr)
  9. shuffled(List list, Random random)