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

Unified Diff: sdk/lib/_collection_dev/iterable.dart

Issue 24740003: Add List.shuffle(). (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Adddress comments Created 7 years, 3 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 | « sdk/lib/_collection_dev/collection_dev.dart ('k') | sdk/lib/_collection_dev/list.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/_collection_dev/iterable.dart
diff --git a/sdk/lib/_collection_dev/iterable.dart b/sdk/lib/_collection_dev/iterable.dart
index 9e7b9902c8a67bda7d2aeef1b37d2f844c08e50b..58f580f3c3761c47e0a27a8bbc1013c68a15414b 100644
--- a/sdk/lib/_collection_dev/iterable.dart
+++ b/sdk/lib/_collection_dev/iterable.dart
@@ -953,6 +953,18 @@ class IterableMixinWorkaround {
Sort.sort(list, compare);
}
+ static void shuffleList(List list) {
+ Random random = new Random();
+ int length = list.length;
+ while (length > 1) {
+ int pos = random.nextInt(length);
+ length -= 1;
+ var tmp = list[length];
+ list[length] = list[pos];
+ list[pos] = tmp;
+ }
+ }
+
static int indexOfList(List list, var element, int start) {
return Arrays.indexOf(list, element, start, list.length);
}
« no previous file with comments | « sdk/lib/_collection_dev/collection_dev.dart ('k') | sdk/lib/_collection_dev/list.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698