Here you can find the source of shuffle(T[] array, Random rand)
Parameter | Description |
---|---|
T | the type of the elements |
array | the array to shuffle |
rand | the random number generator |
public static <T> void shuffle(T[] array, Random rand)
//package com.java2s; //License from project: Open Source License import java.util.Random; public class Main { /**/* w ww . j av a 2s . c o m*/ * Randomly shuffle an array in place. * * @param <T> the type of the elements * @param array the array to shuffle * @param rand the random number generator */ public static <T> void shuffle(T[] array, Random rand) { for (int i = 0; i < array.length; i++) { int index = rand.nextInt(array.length); // Simple swap T temp = array[index]; array[index] = array[i]; array[i] = temp; } } }