I am generating 2 random numbers with Random random = new Random(); to make a random sum. Code:
int min = 5, max = 20
randomNum = random.nextInt((max - min) + 1) + min;
randomNum1 = random.nextInt((max - min) + 1) + min;
Then I display the sum like this:
TextView sumText = (TextView) findViewById(R.id.sumText);
sumText.setText(randomNum + " + " + randomNum1 + " =");
Below the sum is an EditText, and then when I enter the answer it checks if the answer is good, and when it's good it repeats all the code above so a new sum is generated. However, I still have a problem. Sometimes when the sum is generated it generates the same sum as the old sum. How can I let it generate a NEW sum, without it being identical to the previous sum? I think I should do something with the while command but I'm not sure.
Aucun commentaire:
Enregistrer un commentaire