Index: lib/src/utils.dart |
diff --git a/lib/src/utils.dart b/lib/src/utils.dart |
index a1e848156506c4872331fdba328ff56e7e6e934a..569a04f626a2877addfc31c05d873d795deccbd9 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,10 @@ List flatten(Iterable nested) { |
return result; |
} |
+/// Randomly chooses a single element in [elements]. |
+/*=T*/ choose/*<T>*/(List/*<T>*/ elements) => |
+ elements[random.nextInt(elements.length)]; |
+ |
/// Returns a set containing all elements in [minuend] that are not in |
/// [subtrahend]. |
Set setMinus(Iterable minuend, Iterable subtrahend) { |