Here you can find the source of shuffle(int[] ary)
Parameter | Description |
---|---|
ary | a parameter |
public static int[] shuffle(int[] ary)
//package com.java2s; //License from project: Open Source License import java.util.*; public class Main { /**/*from www. j a v a2s . c om*/ * * shuffle * @param ary * @return */ public static int[] shuffle(int[] ary) { return shuffle(0, ary, System.currentTimeMillis()); } /** * * shuffle * * @param start start iundex, which is included. * @param ary * @return */ public static int[] shuffle(int start, int[] ary) { return shuffle(start, ary, System.currentTimeMillis()); } /** * random shuffle inspired by libsvm code * @param ary * @param seed * @return */ public static int[] shuffle(int[] ary, long seed) { return shuffle(0, ary, seed); } /** * random shuffle inspired by libsvm code * * return new int[] instance. * * @param start start index, it is processed. * @param ary * @param seed * @return */ public static int[] shuffle(int start, int[] ary, long seed) { assert start >= 0 && start < ary.length; int len = ary.length; // random shuffle Random rand = new Random(seed); int[] retary = new int[len]; System.arraycopy(ary, 0, retary, 0, len); for (int i = start; i < len; i++) { int j = i + (int) (rand.nextDouble() * (len - i)); int _ = retary[i]; retary[i] = retary[j]; retary[j] = _; } return retary; } }