I have a question about generating numbers without repeating.
I can already generate random numbers from 1 to 8 which is my goal. The odd thing is that it generates repeated numbers (duplicates, triplicates or even more). In my program there can be no number repeated. My code so far:
for (int k = 1; k < (gameBtn.length / 2) + 1; k++) // 1 até 8
{
int z= 8 + (int)(Math.random() * (1 - 8)); // Máximo 8, mínimo 1
gameList.add(z); // Imprime os números de 1 a 8, podendo sair repetidos
}
In other words, I want to make a if (numeros_anteriores_que_sairam != novo numero)
. If it confirms, it prints gameList.add(z)
, otherwise it does not print the number that came out, (or it eliminates equal numbers) or it does something else without printing the number. All numbers must be different!