Here you can find the source of shuffle(short... a)
Parameter | Description |
---|---|
a | the array to shuffle |
public static short[] shuffle(short... a)
//package com.java2s; import java.util.Random; public class Main { private static final Random RAND = new Random(); /**//from w w w . j a v a 2s . c o m * Shuffles the given array randomizing the elements. The argument and return * values are the same for reference. * * @param a the array to shuffle * @return the shuffled array */ public static int[] shuffle(int... a) { for (int i = 0; i < a.length; i++) { int p = RAND.nextInt(a.length); int tmp = a[i]; a[i] = a[p]; a[p] = tmp; } return a; } /** * Shuffles the given array randomizing the elements. The argument and return * values are the same for reference. * * @param a the array to shuffle * @return the shuffled array */ public static short[] shuffle(short... a) { for (int i = 0; i < a.length; i++) { int p = RAND.nextInt(a.length); short tmp = a[i]; a[i] = a[p]; a[p] = tmp; } return a; } /** * Shuffles the given array randomizing the elements. The argument and return * values are the same for reference. * * @param a the array to shuffle * @return the shuffled array */ public static long[] shuffle(long... a) { for (int i = 0; i < a.length; i++) { int p = RAND.nextInt(a.length); long tmp = a[i]; a[i] = a[p]; a[p] = tmp; } return a; } /** * Shuffles the given array randomizing the elements. The argument and return * values are the same for reference. * * @param a the array to shuffle * @return the shuffled array */ public static float[] shuffle(float... a) { for (int i = 0; i < a.length; i++) { int p = RAND.nextInt(a.length); float tmp = a[i]; a[i] = a[p]; a[p] = tmp; } return a; } /** * Shuffles the given array randomizing the elements. The argument and return * values are the same for reference. * * @param a the array to shuffle * @return the shuffled array */ public static double[] shuffle(double... a) { for (int i = 0; i < a.length; i++) { int p = RAND.nextInt(a.length); double tmp = a[i]; a[i] = a[p]; a[p] = tmp; } return a; } /** * Shuffles the given array randomizing the elements. The argument and return * values are the same for reference. * * @param a the array to shuffle * @return the shuffled array */ public static char[] shuffle(char... a) { for (int i = 0; i < a.length; i++) { int p = RAND.nextInt(a.length); char tmp = a[i]; a[i] = a[p]; a[p] = tmp; } return a; } /** * Shuffles the given array randomizing the elements. The argument and return * values are the same for reference. * * @param a the array to shuffle * @return the shuffled array */ public static <T> T[] shuffle(final T... a) { for (int i = 0; i < a.length; i++) { int p = RAND.nextInt(a.length); T tmp = a[i]; a[i] = a[p]; a[p] = tmp; } return a; } }