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

Unified Diff: sdk/lib/collection/list.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/collection.dart ('k') | sdk/lib/core/list.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/collection/list.dart
diff --git a/sdk/lib/collection/list.dart b/sdk/lib/collection/list.dart
index 0e0c6116445554ade256019919d6f97b991f0044..74cda1df9427ac81e091679df912bba3f770520a 100644
--- a/sdk/lib/collection/list.dart
+++ b/sdk/lib/collection/list.dart
@@ -301,6 +301,18 @@ abstract class ListMixin<E> implements List<E> {
Sort.sort(this, compare);
}
+ void shuffle() {
+ Random random = new Random();
+ int length = this.length;
+ while (length > 1) {
+ int pos = random.nextInt(length);
+ length -= 1;
+ var tmp = this[length];
+ this[length] = this[pos];
+ this[pos] = tmp;
+ }
+ }
+
Map<int, E> asMap() {
return new ListMapView(this);
}
« no previous file with comments | « sdk/lib/collection/collection.dart ('k') | sdk/lib/core/list.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698