Last active
June 7, 2019 12:40
-
-
Save th4deu/7bfc141f56f4ca7c36fcd506db8af2e2 to your computer and use it in GitHub Desktop.
Gerador de numero aleatorio em dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
generate a random number in DART also giving the option to get a name from an array. | |
try it in https://dartpad.dartlang.org/. :) | |
*/ | |
import 'dart:math'; | |
void main() { | |
Random _random = Random(); | |
int randomNumber(int min, int max) => min + _random.nextInt(max - min); | |
int qty, from, to; | |
qty = 2; | |
from = 0; | |
to = 6; | |
var names = ['name a', 'name b', 'name c', 'name d', 'name e', 'name f']; | |
for (int i = 0; i < qty; i++) { | |
int selectedNumber = randomNumber(from, to); | |
print("selected number: " + selectedNumber.toString()); | |
print("name in number's position: " + names[selectedNumber]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment