Java examples for Collection Framework:Array Random Value
random Int Array
//package com.java2s; import java.util.HashSet; import java.util.Random; public class Main { public static void main(String[] argv) { int size = 42; System.out.println(java.util.Arrays.toString(randomIntArray(size))); }/*from ww w . j av a 2s . c o m*/ public static Integer[] randomIntArray(int size) { Integer a[] = new Integer[size]; HashSet<Integer> set = new HashSet<>(); for (int x = 0; x < a.length; x++) { Random r = new Random(); Integer i = r.nextInt(size * 10); while (set.contains(i)) { i = r.nextInt(size); } set.add(i); a[x] = i; } return a; } }