Java Array Shuffle shuffle(List list)

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

Description

Shuffle the given list in-place.

License

LGPL

Parameter

Parameter Description
T the list type
list the list to shuffle

Return

the list

Declaration

public static <T> List<T> shuffle(List<T> list) 

Method Source Code

//package com.java2s;
/*//from   w  w  w . jav a2  s  .  co  m
 * Copyright 2008-2014, David Karnok 
 * The file is part of the Open Imperium Galactica project.
 * 
 * The code should be distributed under the LGPL license.
 * See http://www.gnu.org/licenses/lgpl.html for details.
 */

import java.util.Collections;

import java.util.List;

import java.util.Random;

public class Main {
    /**
     * The random number generator for simulation/AI activities.
     */
    public static final ThreadLocal<Random> RANDOM = new ThreadLocal<Random>() {
        @Override
        public Random get() {
            return new Random();
        }
    };

    /**
     * Shuffle the given list in-place.
     * @param <T> the list type
     * @param list the list to shuffle
     * @return the list
     */
    public static <T> List<T> shuffle(List<T> list) {
        Collections.shuffle(list, RANDOM.get());
        return list;
    }
}

Related

  1. shuffle(Integer[] data)
  2. shuffle(List list)
  3. shuffle(List list)
  4. shuffle(List list, Random rnd)
  5. shuffle(List as)
  6. shuffle(List list)
  7. shuffle(List list, int nswaps)
  8. shuffle(Object[] a)
  9. shuffle(Object[] a, Random r)