Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(466)

Unified Diff: lib/src/utils.dart

Issue 1852513004: Make life a little more sparkly. (Closed) Base URL: git@github.com:dart-lang/pub.git@master
Patch Set: Code review changes Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/src/log.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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) {
« no previous file with comments | « lib/src/log.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698