I'm in the process of creating a program that generates 50 random numbers between 1-999, but I can't figure out how to stop duplicates from showing up in the program. Any help would be appreciated.
public class Random50 //Name of my class
{
public static void main(String[] args)
{
int[] randomArray; //Declares a new array of integers
randomArray = new int[51];
Random rand = new Random();
for (int i = 1; i < randomArray.length; i++)
{
int n = rand.nextInt(1000);
randomArray[i] = n;
}
for (int i = 1; i < randomArray.length; i++) 4
{
System.out.printf("Number " + i + ": " + "%03d\n", randomArray[i]);
}
}
}