Here you can find the source of randomRange(int end)
public static int[] randomRange(int end)
//package com.java2s; //License from project: Open Source License import java.util.*; public class Main { public static int[] randomRange(int end) { return randomRange(end, System.currentTimeMillis()); }/*w w w . j av a 2s . c o m*/ public static int[] randomRange(int end, long seed) { int[] ary = range(end); return shuffle(ary, seed); } public static int[] range(int end) { assert end > 0; int[] ary = new int[end]; for (int i = 0; i < end; ++i) { ary[i] = i; } return ary; } public static int[] range(int start, int end) { int l = end - start; assert l > 0; int[] ary = new int[l]; for (int i = 0; i < l; ++i) { ary[i] = i + start; } return ary; } /** * * 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; } }