Here you can find the source of shuffle(List
Parameter | Description |
---|---|
T | the list type |
list | the list to shuffle |
public static <T> List<T> shuffle(List<T> list)
//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; } }