Here you can find the source of makeRandomList(int arraySize, boolean unique)
public static ArrayList<Integer> makeRandomList(int arraySize, boolean unique)
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; import java.util.HashSet; import java.util.Random; public class Main { public static Random r = new Random(); public static ArrayList<Integer> makeRandomList(int arraySize, boolean unique) { int[] values = makeRandomArray(arraySize, unique); ArrayList<Integer> result = new ArrayList<Integer>(); for (int i = 0; i < values.length; i++) { result.add(values[i]);//from ww w . j a v a 2s . com } return result; } public static int[] makeRandomArray(int arraySize, boolean unique) { int[] values = new int[arraySize]; HashSet<Integer> used = new HashSet<Integer>(); for (int i = 0; i < arraySize; i++) { int toInsert = r.nextInt(10000); while (unique && used.contains(toInsert)) { toInsert = r.nextInt(10000); } values[i] = toInsert; used.add(toInsert); } return values; } }