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

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: 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
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..edbbfd84c1801a00a19ad9ddd3a327ee1b65be11 100644
--- a/sdk/lib/_collection_dev/iterable.dart
+++ b/sdk/lib/_collection_dev/iterable.dart
@@ -953,6 +953,17 @@ class IterableMixinWorkaround {
Sort.sort(list, compare);
}
+ static void shuffleList(List list) {
+ Random random = new Random();
+ int length = list.length;
+ while (--length > 0) {
+ int pos = random.nextInt(length);
+ 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);
}

Powered by Google App Engine
This is Rietveld 408576698