Java tutorial
//package com.java2s; import java.util.HashSet; import java.util.Set; public class Main { public static Set<Integer> randomSetRange(int min, int max, int n) { Set<Integer> set = new HashSet<Integer>(); while (set.size() < n) { int num = (int) (Math.random() * (max - min)) + min; set.add(num); } return set; } }