I have a random dice generator with 2 dice. I’m using a compare statement to check the random result of the two dice and re roll if they are the same. here is the code to roll one of the dice
void Roll1() {
setState(() {
oneDiceNumber = Random().nextInt(6) + 1;
if (oneDiceNumber == twoDiceNumber) {
oneDiceNumber = Random().nextInt(6) + 1;
twoDiceNumber = Random().nextInt(6) + 1;
}
});
}
what I want the code to do is loop the if statement until it gets a result that isn’t a tie.
thanks so much
2
Answers
Try a while loop
You could also do this using
recursion
:Define a function called getRandomDice():
and you could call this using in your function like this: