Here you can find the source of Shuffle(double[] array)
Parameter | Description |
---|---|
array | Array. |
public static void Shuffle(double[] array)
//package com.java2s; // under the BSD license. The original license terms are given below: import java.util.Random; public class Main { /**//from w w w . j a v a2s . co m * Shuffle an array. * @param array Array. */ public static void Shuffle(double[] array) { Shuffle(array, 0); } /** * Shuffle an array. * @param array Array. * @param seed Random seed. */ public static void Shuffle(double[] array, long seed) { Random random = new Random(); if (seed != 0) random.setSeed(seed); for (int i = array.length - 1; i > 0; i--) { int index = random.nextInt(i + 1); double temp = array[index]; array[index] = array[i]; array[i] = temp; } } /** * Shuffle an array. * @param array Array. */ public static void Shuffle(int[] array) { Shuffle(array, 0); } /** * Shuffle an array. * @param array Array. * @param seed Seed of the random. */ public static void Shuffle(int[] array, long seed) { Random random = new Random(); if (seed != 0) random.setSeed(seed); for (int i = array.length - 1; i > 0; i--) { int index = random.nextInt(i + 1); int temp = array[index]; array[index] = array[i]; array[i] = temp; } } /** * Shuffle an array. * @param array Array. * @param seed Random seed. */ public static void Shuffle(float[] array, long seed) { Random random = new Random(); if (seed != 0) random.setSeed(seed); for (int i = array.length - 1; i > 0; i--) { int index = random.nextInt(i + 1); float temp = array[index]; array[index] = array[i]; array[i] = temp; } } }