Java tutorial
import java.util.Arrays; import java.util.Random; public class Main { public static void main(String args[]) { int rnd; Random rand = new Random(); int[] nums = new int[50]; boolean[] check = new boolean[50]; for (int k = 0; k < 50; k++) { rnd = rand.nextInt(50); //check if the check array index has been set //if set regenerate since it is duplicate while (check[rnd]) { rnd = rand.nextInt(50); } nums[k] = rnd; check[rnd] = true; } System.out.println(Arrays.toString(nums)); } }