Java tutorial
import java.util.Arrays; import java.util.HashSet; import java.util.Random; import java.util.Set; public class Main { public static void main(final String[] args) throws Exception { Random random = new Random(); Set<Integer> intSet = new HashSet<>(); while (intSet.size() < 6) { intSet.add(random.nextInt(49) + 1); } Integer[] ints = intSet.toArray(new Integer[intSet.size()]); System.out.println(Arrays.toString(ints)); } }