Random Number Generation Repeating | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
+ 1

Random Number Generation Repeating

while (true) { cpuLetterGuess = (int) (Math.random() * 10); cpuNumGuess = (int) (Math.random() * 10); if (!(cpuGuesses.contains((char)(cpuLetterGuess + 65) + " " + cpuNumGuess))) { cpuGuesses += "" + ((char) (cpuLetterGuess + 65)) + cpuNumGuess ; System.out.print(cpuGuesses); break; } } Hey all, so I'm tryna prevent the computer from selecting the same coordinates twice from my array. This is my code so far but the randomiser still repeats. Why is that? Thanks for the help guys :)

18th Mar 2018, 6:38 PM
Daniel Zhang
Daniel Zhang - avatar
0 Réponse