Chromium Code Reviews| Index: lib/src/utils.dart |
| diff --git a/lib/src/utils.dart b/lib/src/utils.dart |
| index a1e848156506c4872331fdba328ff56e7e6e934a..aa49710faf9dd94835bdd5b20d5be5b5010b3f3f 100644 |
| --- a/lib/src/utils.dart |
| +++ b/lib/src/utils.dart |
| @@ -6,6 +6,7 @@ |
| import 'dart:async'; |
| import "dart:convert"; |
| import 'dart:io'; |
| +import 'dart:math' as math; |
| import "package:crypto/crypto.dart"; |
| import 'package:path/path.dart' as path; |
| @@ -34,6 +35,9 @@ const reservedWords = const [ |
| "var", "void", "while", "with" |
| ]; |
| +/// An cryptographically secure instance of [math.Random]. |
| +final random = new math.Random.secure(); |
| + |
| /// A pair of values. |
| class Pair<E, F> { |
| E first; |
| @@ -287,6 +291,9 @@ List flatten(Iterable nested) { |
| return result; |
| } |
| +/// Randomly chooses a single element in [elements]. |
| +choose(List elements) => elements[random.nextInt(elements.length)]; |
|
Bob Nystrom
2016/04/01 20:35:27
Make this a generic method. :)
nweiz
2016/04/01 20:38:16
Done.
|
| + |
| /// Returns a set containing all elements in [minuend] that are not in |
| /// [subtrahend]. |
| Set setMinus(Iterable minuend, Iterable subtrahend) { |