pedro_bb7
pedro_bb7

Reputation: 2091

Returning two integers in the same function

I created the following function to return two random integer values:

List<int> randomGenerator() {
  return [(Random().nextInt(6) + 1),(Random().nextInt(6) + 1)];
}

And want to set to two program variables (left and right dice).

So tried by executing:

[rightDiceNumber,leftDiceNumber] = randomGenerator();

But it didn't work.

Upvotes: 1

Views: 215

Answers (1)

MSARKrish
MSARKrish

Reputation: 4094

you can get your return value like this

List randomValues;
randomValues=randomGenerator();
print(randomValues[0]);
print(randomValues[1]);  

Upvotes: 1

Related Questions