Skip to content

Instantly share code, notes, and snippets.

@Davis-Desormeaux
Created April 22, 2012 00:46
Show Gist options
  • Save Davis-Desormeaux/2440560 to your computer and use it in GitHub Desktop.
Save Davis-Desormeaux/2440560 to your computer and use it in GitHub Desktop.
Dart Lotto Picker
// Dart code snippet to get next week's winning lottery numbers
// by taking a random guess...
// dartbit.com
final int out_of_nbs = 6; // Total numbers required to play.
final int number_max = 40; // NYC lotto game (Sweet Million)
//final int number_max = 49; // CAN lotto game (The Lotto 6/49)
/*
* Returns a random [int] between 1 and [int] 'max_inclusive'.
*/
int ceil_rand (int max_inclusive) {
return ((Math.random() * max_inclusive).ceil()).toInt();
}
/*
* Returns a new [int] that is not inside the [Set].
*/
int pick_a_number(Set the_lotto_picks) {
int one_lotto_number = ceil_rand(number_max);
if (the_lotto_picks.contains(one_lotto_number)) // Keep a recursion until
one_lotto_number = pick_a_number(the_lotto_picks); // a new nb is found
return one_lotto_number;
}
main() {
Set the_picks = new Set();
while (the_picks.length < out_of_nbs) the_picks.add(pick_a_number(the_picks));
for (int this_loto_nber in the_picks) print(this_loto_nber); // Print numbers.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment