Skip to content

Instantly share code, notes, and snippets.

@th4deu
Last active June 7, 2019 12:40
Show Gist options
  • Save th4deu/7bfc141f56f4ca7c36fcd506db8af2e2 to your computer and use it in GitHub Desktop.
Save th4deu/7bfc141f56f4ca7c36fcd506db8af2e2 to your computer and use it in GitHub Desktop.
Gerador de numero aleatorio em dart
/*
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