I want to generate random number from 1 to 9 and i want them to be unique. This is the code i have written which gives me 9 different numbers from 1 to 9 but I have no clue on generating unique number.
int data[] = new int[10];
for(int i = 0; i < data.length; i++) {
Random randomGenerator = new Random();
data[i] = randomGenerator.nextInt(10);
System.out.println(data[i]);
}
Aucun commentaire:
Enregistrer un commentaire