Here you can find the source of shuffle(int size, boolean reallyShuffle)
public static ArrayList<Integer> shuffle(int size, boolean reallyShuffle)
//package com.java2s; import java.util.ArrayList; import java.util.HashSet; import java.util.Random; public class Main { public static ArrayList<Integer> shuffle(int size, boolean reallyShuffle) { ArrayList<Integer> result = new ArrayList<Integer>(); if (reallyShuffle) { HashSet<Integer> shuffled = new HashSet<Integer>(); Random r = new Random(); while (result.size() != size) { int i = r.nextInt(size); if (shuffled.add(i)) { result.add(i);//from w w w. jav a2 s .com } } } else { for (int i = 0; i < size; i++) result.add(i); } return result; } }